Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Created June 7, 2013 21:50
Show Gist options
  • Save skratchdot/5732659 to your computer and use it in GitHub Desktop.
Save skratchdot/5732659 to your computer and use it in GitHub Desktop.
jquery.pruneSiblings plugin - takes a selector and walks up the dom tree (until reaching a body or html tag), removing siblings along the way.
/*globals jQuery */
(function ($) {
'use strict';
var prune = function (orig, item) {
var parent = item.parent();
item.siblings().remove();
if (parent.length > 0 && !parent.is('body') && !parent.is('html')) {
return prune(orig, parent);
}
return orig;
};
$.fn.pruneSiblings = function() {
return prune(this, this);
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment