Given the following HTML:
<ul>
<li class="">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<ul>
<li class="selected">1a</li>
<li>2a</li>
<li>3a</li>
<li>4a</li>
<li>5a</li>
</ul>
I'm trying to get the index of the selected element, among all LIs. This works:
$('ul li').index($('ul .selected')) -> 5
But in seems natural (and consistent with other methods like find() and filter()) to do this:
$('ul li').index('.selected') -> -1
Unfortunately that doesn't work. I understand that the index() is documentation (though confusing) correctly tells you that the above code doesn't work. Maybe I'm just weird, but I feel that the way .index() is implemented for string arguments is very counter intuitive. I guess I have an expectation that .index() is similar to indexOf() in javascript.