Created
July 11, 2013 15:19
-
-
Save ebinnion/5976396 to your computer and use it in GitHub Desktop.
Snippet will return a 1-based-index of an element in relation to like tags at same level.
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
// Return 1-based-index of an element in relation to like tags | |
function indexOfType(element) { | |
var prev = element.prevAll(element[0].tagName); | |
if ( empty(prev) ){ | |
return 1; // For 1 indexing | |
} | |
else return 1 + prev.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment