Created
May 26, 2010 11:51
-
-
Save joneff/414384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
details, summary {display: block;} | |
details:not([open]) > :not(summary) {display: none;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype> | |
<html> | |
<head> | |
<title>Details element</title> | |
<style> | |
details, summary {display: block;} | |
details:not([open]) > :not(summary) {display: none;} | |
</style> | |
</head> | |
<body> | |
<details> | |
<summary>SUMMARY</summary> | |
<p>Other content</p> | |
<p>Other content</p> | |
<p>Other content</p> | |
</details> | |
<script> | |
if (!("open" in document.createElement("details"))) { | |
var summaries = document.querySelectorAll("details > summary"); | |
document.body.addEventListener("click", function(event) { | |
var target = event.target; | |
for (var i = 0, l = summaries.length; i < l; i++) { | |
if (target == summaries[i]) { | |
var parent = target.parentNode; | |
if (parent.hasAttribute("open")) { | |
parent.removeAttribute("open"); | |
} else { | |
parent.setAttribute("open", "open"); | |
} | |
} | |
} | |
}, false); | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!("open" in document.createElement("details"))) { | |
var summaries = document.querySelectorAll("details > summary"); | |
for (var i = 0; i < summaries.length; i++) { | |
var summary = summaries[i]; | |
summary.addEventListener("click", function() { | |
var parent = summary.parentNode; | |
if (parent.hasAttribute("open")) { | |
parent.removeAttribute("open"); | |
} else { | |
parent.setAttribute("open", "open"); | |
} | |
}, false); | |
} | |
} |
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
Point taken