Monday, June 25, 2007

Get the index number of an element

Heres a little gem I found at :
http://forums.htmlhelp.com/lofiversion/index.php/t746.html

This short little javascript allows you to detect / retrieve / get the index number of an element. Which can defiantly be useful in a number of different applications.

var p=document.getElementsByTagName('p');
for(var i=0; i
{
p[i].pnum=i;
p[i].onclick=function()
{
alert(this.pnum);
}
}

No comments: