You are teh hotness John :D Thanks for that. I've been racking the cabeza for quite a while trying to get that one :)
John Resig wrote: > > You want the index() function: > > var item = $("li.selected")[0]; > var position = $("li").index( item ); > > On 3/23/07, Nate Cavanaugh <[EMAIL PROTECTED]> wrote: >> >> Hi all, >> I'm looking to find the current numeric position of a certain element >> amongst it's siblings. >> >> Let's say I have a list like so: >> >> <ul> >> <li>Test 1</li> >> <li>Test 2</li> >> <li class="selected">Test 3</li> >> <li>Test 4</li> >> <li>Test 5</li> >> </ul> >> >> So, I grab $('li.selected'). I now want to find out what number it is (in >> this case, I would want it to return 3). >> >> Currently, I am doing it this way, but I am hoping for a more >> jQuery-esque >> way: >> >> var item = $('li.selected')[0]; >> var position = 1; >> $('li').each(function() { >> if(this != item){ >> position++; >> }else { >> return false; >> } >> }); >> >> Seems a bit ugly, but it could be the only way, I dunno. >> >> Anyone have any thoughts? >> -- >> View this message in context: >> http://www.nabble.com/Best-way-to-find-current-position-in-DOM-stack--tf3455334.html#a9639907 >> Sent from the JQuery mailing list archive at Nabble.com. >> >> >> _______________________________________________ >> jQuery mailing list >> discuss@jquery.com >> http://jquery.com/discuss/ >> > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/Best-way-to-find-current-position-in-DOM-stack--tf3455334.html#a9645062 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/