Skip to content

Instantly share code, notes, and snippets.

@Anima-t3d
Forked from anonymous/jquery.deepest.js
Created June 8, 2011 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anima-t3d/1014671 to your computer and use it in GitHub Desktop.
Save Anima-t3d/1014671 to your computer and use it in GitHub Desktop.
jQuery 'deepest' plugin
$.fn.deepest = function() {
/* based on: http://stackoverflow.com/questions/3787924/select-deepest-child-in-jquery
* rewrite from: https://gist.github.com/714851
* rewritten by: Anima-t3d march 1st 2011
*/
/// <summary>
/// Return the deepest child of this element.
/// var deepestElement = $("div").deepest();
/// For example, when run on this structure:
///
/// <div>
/// <span> <b>pick me!</b> </span>
/// <span> </span>
/// </div>
///
/// It would return the element:
/// alert(deepestElement);
/// <b>pick me!</b>
/// </summary>
var $target = $(this).children();
while( $target.length ) {
$target = $target.children();
}
return $target.end();
};
@martinille
Copy link

This plugin seems to be more complex and has a little more functionality: https://github.com/martinille/jquery.deepest.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment