I am making a function for my site where I set a data attribute which contains the nth-child number of that element.
My HTML markup:
<
Check out this previous answer HERE.
It uses
var i = 0; while( (child = child.previousSibling) != null ) i++; //at the end i will contain the index.