Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
details:not([open]) > :not(summary) {display: none;}
@mathiasbynens

This comment has been minimized.

Show comment Hide comment
@mathiasbynens

mathiasbynens Aug 29, 2011

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 :)

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

This comment has been minimized.

Show comment Hide comment
@joneff

joneff 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.

Owner

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

This comment has been minimized.

Show comment Hide comment
@mathiasbynens

mathiasbynens Aug 29, 2011

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!

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

This comment has been minimized.

Show comment Hide comment
@joneff

joneff 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

Owner

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

This comment has been minimized.

Show comment Hide comment
@mathiasbynens

mathiasbynens Aug 29, 2011

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

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