Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery contains

Tags:

jquery

Is there a way to get the deepest element matching a contains statement?

Basicly if I have nested divs, I want the last element not the parent element:

<div id="hayStack">
  <div id="needle">Needle</div>
</div>

$("div:contains('Needle')") is returning the hayStack div.

The only solution I have come up with so far is explicitly exlcuding parent divs by their id with .not

like image 306
Domtar Avatar asked Dec 08 '22 05:12

Domtar


1 Answers

Adding :last will return the deepest/last div (the one immedietly encapsulating the content you are searching for

$("div:contains('Needle'):last")
like image 195
duckyflip Avatar answered Dec 29 '22 19:12

duckyflip