select an element in javascript/jquery by its html content

Imagine I have the following HTML:

<div>
     <p> text 1 </p>
     .. some content ..
</div>

<div>
     <p> text 2 </p>
     .. some content ..
</div>

I want to select the divs by the content of text, is it possible ? and how can id do it ? thanks !!

Upvotes: 1

Views: 71

Answers (1)

Anto king
Anto king

Reputation: 1222

Yes possible, Try something like this

$( "div:contains('John')" ).css( "text-decoration", "underline" );
$('div:contains("test")').css('background-color', 'blue');

Same thing explained here as detail Selector

Upvotes: 1

Related Questions