Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all divs in a particular div using JQuery

Tags:

jquery

I have this document structure

<div id="log">
<div>ABC</div>
<br/>
<div>DEF</div>
<br/>
...
</div>

Where ... represents any number of div, br pairs.

Now I need to write a JQuery function called exists that takes an id (in this case "log") and a string (for example "DEF") and checks if in the "log" div there is any div whose text matches "DEF". My JQuery is weak, can someone help me with this?

like image 788
Sachin Kainth Avatar asked Dec 27 '22 18:12

Sachin Kainth


1 Answers

if ( $('#log div:contains("DEF")').length ) {
   // exists
}
like image 174
undefined Avatar answered Dec 29 '22 11:12

undefined