Created
February 5, 2018 18:57
-
-
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
This file contains hidden or 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
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