Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  108] [ 2]  / answers: 1 / hits: 21576  / 12 Years ago, wed, may 2, 2012, 12:00:00

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


More From » jquery

 Answers
16

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'));



[#85858] Monday, April 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;