tags:

views:

60

answers:

3

The NodeList don't have a indexOf(element) method? So, how can I get the element index?

+1  A: 

By iterating over the elements, and checking if it matches

Martijn
A: 

The NodeList objet is an Array-like object. So it's possible to "convert" it into an Array.

Maybe it can be a solution for you.

var arr = Array.prototype.slice.call(yourNodeListObject); // Now it's an Array.
arr.indexOf(element); // The index of your element :)
Golmote
+1  A: 

if you have an indexOf method, native or shimmed, you can call it on a nodeList without having to convert the node list to an array.

var N= document.getElementsByTagName('*');
alert(Array.prototype.indexOf.call(N, document.body));
kennebec
Hm... I never realised that. Thank you for pointing it out :)
Golmote