You could do something like this: $('p').click(function() { console.log( $('p').index(this) ); });
Or you could use an each() method, which has a built-in index argument: $('p').each(function(index) { $(this).click(function() { console.log(index); }); }); --Karl ____________ Karl Swedberg www.englishrules.com www.learningjquery.com On Nov 13, 2008, at 11:42 AM, Logictrap wrote:
Is there a simple method for determining the element number for a click event? Using this html code: <P>Some Text</P> <P>Some Text</P> <P>Some Text</P> <P>Some Text</P> <P>Some Text</P> Is there a click event that will tell you the element number of which <P> was clicked on starting with 0 as the first one? ie if you clicked on the first element it would tell you "element 0 clicked", if you clicked on the second element it would tell you "element 1 clicked" I figured out a way to do this by assigning an id to each <P> but I was hoping there was a way to not need the id. Thanks