Normally I'm doing it this way:
for(i=0;i<elem.parentNode.length;i++) { if (elem.parentNode[i] == elem) //.... etc.. etc... }
You could count siblings... The childNodes list includes text and element nodes-
function whichChild(elem){ var i= 0; while((elem=elem.previousSibling)!=null) ++i; return i; }
2.1m questions
2.1m answers
60 comments
56.8k users