Skip to content

Instantly share code, notes, and snippets.

@joneff
Created May 26, 2010 11:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joneff/414384 to your computer and use it in GitHub Desktop.
Save joneff/414384 to your computer and use it in GitHub Desktop.
details:not([open]) > :not(summary) {display: none;}
@mathiasbynens
Copy link

For future reference, this fallback is only targeted at modern browsers. .querySelectorAll and .hasAttribute are only supported in IE8+. addEventListener works in IE9+.

Also it won’t take care of the edge case where direct child text nodes are part of the <summary> (as the CSS rule details:not([open]) > :not(summary) {display: none;} won’t target those).

If you ever need a more robust (but slightly heavier) solution, feel free to use http://mathiasbynens.be/notes/html5-details-jquery :)

@joneff
Copy link
Author

joneff commented Aug 29, 2011

And so is :not ;)

If I was worrying about IE6 not being able to display this snippet, I wouldn't have written in the first place. Sometimes (especially when possible) one should really take advantage of technology regardless the legacy players out there.

@mathiasbynens
Copy link

If I was worrying about IE6 not being able to display this snippet, I wouldn't have written in the first place.

Sure — please don’t get me wrong, I’m just pointing it out so less experienced developers don’t get bitten by the lack of browser support. If you only need to support modern browsers (and you don’t need to account for every possible edge case), this is a lovely lightweight snippet!

@joneff
Copy link
Author

joneff commented Aug 29, 2011

Also it won’t take care of the edge case where direct child text nodes are part of the

(as the CSS rule details:not([open]) > :not(summary) {display: none;} won’t target those).

Point taken

@mathiasbynens
Copy link

Btw, the code in the separate .js seems to differ from the JavaScript in the HTML. Just a heads up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment