Skip to content

Instantly share code, notes, and snippets.

@stephenorem
Created February 5, 2018 18:57
Show Gist options
  • Save stephenorem/5162a871c5d96bfa522e31ede6205e51 to your computer and use it in GitHub Desktop.
Save stephenorem/5162a871c5d96bfa522e31ede6205e51 to your computer and use it in GitHub Desktop.
searchDepth - find the depth of nested html elements; for example, ul/ol - uses jQuery
function searchDepth() {
var maxDepth = 0,
d,
parents,
myselector = 'ul, ol';
$(myselector).each( function(i) {
parents = $(this).parents(myselector);
d = parents ? parents.length + 1 : 1;
maxDepth = d > maxDepth ? d : maxDepth;
});
return maxDepth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment