The NodeList don't have a indexOf(element) method? So, how can I get the element index?
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
2010-09-23 16:02:10
+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
2010-09-23 17:32:02
Hm... I never realised that. Thank you for pointing it out :)
Golmote
2010-09-24 00:29:49