Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2011 09:23
Show Gist options
  • Save anonymous/1178074 to your computer and use it in GitHub Desktop.
Save anonymous/1178074 to your computer and use it in GitHub Desktop.
Wrap box for my current project
$('.borderedBox, #content').each(function(){
var t = $(this),
mainClasses = this.className,
mainIds = this.id;
if (mainClasses.length > 0 && !mainIds.length) { //Wrap for elements which has only class
t.wrap('<div class="'+mainClasses+'" />');
}
if (mainClasses.length > 0 && mainIds.length > 0) { //Wrap for elements which has both, class and id
t.wrap('<div class="'+mainClasses+'" id="'+mainIds+'" />');
}
if (mainIds.length > 0 && !mainClasses.length) { //Wrap for elements which has only id
t.wrap('<div id="'+mainIds+'" />');
}
t.removeAttr('class'); //Remove class attribute from original element
t.removeAttr('id'); //Remove id attribute from original element
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment