Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find indexOf element in jQuery array?

I have two selectors

    var allNodes = $("a.historyEntry");
    var errorNodes = $("a.historyEntry.error");

I would like to to find a node before first error node, so I need to find an index of first error node, how to do it?

I tried to use inArray method, but it doesn't work for this

$.inArray(allNodes, errorNodes.first())

or

$.inArray(allNodes, $(errorNodes.first()))

Is there any fast way to do it in jQuery or do I have to use for loop?

like image 787
IAdapter Avatar asked Dec 09 '22 05:12

IAdapter


1 Answers

index()?

It's like indexOf... but just without the Of... it returns the index of the element if it exists, and -1 if it doesn't.

like image 87
Matt Avatar answered Dec 27 '22 13:12

Matt