Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery indexOf function?

I'm trying to get a location of an element in a jQuery set.

Here's what I tried so far.

I want to be able to do something like this:

$('ul').find('a').indexOf('.active');

And get the location of the .active in the set of a's.

Is there something like an indexOf() function for jQuery? The index() method doesn't work

like image 924
qwertymk Avatar asked May 02 '12 00:05

qwertymk


1 Answers

if you pass a jQuery set ($searchFor) as an argument to the index method of another jQuery set ($searchIn) i.e.

$searchIn.index($searchFor)

it will return the index of $searchFor in the set $searchIn

In your example:

$('ul a').index($('ul a.active'));

like image 147
tobyodavies Avatar answered Sep 27 '22 21:09

tobyodavies