Last active
November 16, 2017 05:45
-
-
Save conectado/b6b794bb45b1c82022e38d56872dcf2c to your computer and use it in GitHub Desktop.
Getting the children of a jQuery object recursively and applying a callback.
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
//Adding to jQuery prototype | |
//Recursively applies callback to all children of a given jQuery object. | |
(function ($) { | |
$.fn.recursiveChildren = function (callback) { | |
$(this).children().each( | |
function() | |
{ | |
//If it has any children | |
if($(this).children.length > 0) | |
{ | |
$(this).recursiveChildren(callback); | |
} | |
callback($(this)); | |
} | |
); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment