Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery retrieving index on hasClass

Tags:

jquery

Is it possible to get the index on the first instance of a hasClass?

For Example:

$(".class").children().hasClass('classname').index();

Unfortunately this doesn't work.

like image 337
zman0404 Avatar asked Dec 14 '25 04:12

zman0404


1 Answers

.hasClass returns a boolean, you can filter the results of .children to those that have the classname-class and then get the index:

$(".class").children(".classname").index();
like image 104
Esailija Avatar answered Dec 15 '25 18:12

Esailija