test
test

Reputation: 2466

find index of div that has specific class name

How can I find div's index that has specific class name using each? here is html:

<div class="">text1</div>
<div class="">text2</div>
<div class="active">text3</div>
<div class="">text4</div>
<div class="">text5</div>
<div class="">text6</div>

So basicly i needto find class name and then find his div index number? any suggestions? Thanks!

Upvotes: 0

Views: 304

Answers (1)

Adriano Carneiro
Adriano Carneiro

Reputation: 58615

You don't need each for that just do this:

$("div.active").index();

Here, have a fiddle: http://jsfiddle.net/adrianonantua/SKBvW/

Keep in mind that the returned index is zero based, thus the code will return 2 for the posted HTML, because it's the third div.

Upvotes: 2

Related Questions