Skip to content

Instantly share code, notes, and snippets.

@hay
Created December 20, 2010 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hay/748596 to your computer and use it in GitHub Desktop.
Save hay/748596 to your computer and use it in GitHub Desktop.
A jQuery plugin that enables the behaviour of the HTML5 <details> and <summary> elements.
(function($) {
$.detailsShim = function() {
$("details").each(function() {
// Initial state of all elements in <section>
var initOpen = ($(this).attr('open') === "true") ? true : false;
$(this).children(":not(summary)").each(function() {
$(this).toggle(initOpen);
});
// Click event on <summary> toggles all elements
$("summary").click(function(e) {
e.preventDefault();
$(this).nextAll().toggle();
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment