Hi Nate,
Give this one a shot:
$('li').each(function(index){
if($(this).is('.selected')) {
alert(index+1);
};
});
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Mar 23, 2007, at 1:41 PM, Nate Cavanaugh 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/