-1

I have a kind of unique need of finding one div on all divs with same class name that has a specific copy, and return the entry number:

<div class="alertme"></div>
<div class="alertme"></div>
<div class="alertme">This text</div>
<div class="alertme"></div>

So it would return 2, being 0 is the first div.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Nuno Luz
  • 97
  • 1
  • 1
  • 6

1 Answers1

1

I'm not sure if that what you want, but to get the index of the div that has the This text text you could use :contains selector with .index() method :

$('.alertme:contains("This text")').index();

Hope this helps.

console.log($('.alertme:contains("This text")').index());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="alertme"></div>
<div class="alertme"></div>
<div class="alertme">This text</div>
<div class="alertme"></div>
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101