Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created July 11, 2013 15:19
Show Gist options
  • Save ebinnion/5976396 to your computer and use it in GitHub Desktop.
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.
// 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