Last active
December 17, 2015 10:09
-
-
Save barneycarroll/5593167 to your computer and use it in GitHub Desktop.
$(selection).reverse(fn) applies the passed function to each element in each element in the selection recursively, starting with the bottom of the tree. Useful for cleaning out empty elements recursively (such that an empty div will be destroyed, then the parent it is only child of will be destroyed too, etc).
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
$.fn.reverse = function(fn){ | |
return this.each(function(el, i){ | |
var $all = $('<x>').append(el).find('*'); | |
fn.call([].reverse.call($all)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment