Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  82] [ 2]  / answers: 1 / hits: 36433  / 14 Years ago, mon, january 10, 2011, 12:00:00

Normally I'm doing it this way:



for(i=0;i<elem.parentNode.length;i++) {
if (elem.parentNode[i] == elem) //.... etc.. etc...
}

More From » dom

 Answers
10

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;
}

[#94294] Saturday, January 8, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rafael

Total Points: 5
Total Questions: 103
Total Answers: 103

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;