Created
June 7, 2013 21:50
-
-
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.
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
/*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