Skip to content

Instantly share code, notes, and snippets.

@bfintal
Created September 30, 2011 04:47
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 bfintal/1252686 to your computer and use it in GitHub Desktop.
Save bfintal/1252686 to your computer and use it in GitHub Desktop.
Automatically wraps groups of headings (h1, h2, h3, h4, h5 and h6) into hgroups. Good for HTML5 styling.
jQuery(document).ready(function($){
var skip = 0;
$('h1, h2, h3, h4, h5, h6').each(function(i) {
if (skip > 0) {
skip--;
return;
}
var group = $(this).add($(this).nextUntil(':not(h1, h2, h3, h4, h5, h6)'));
skip = group.length - 1;
if (group.length > 1) {
if (group.parent().length && !group.parent().is('hgroup')) {
group.wrapAll('<hgroup/>');
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment