Pseudo-class :contains in jQuery
The pseudo-class contains
selects elements based on the presence of certain text in them.
In the following example, we have a paragraph that contains the word 'text'
:
<p>test "text"</p>
<p>test</p>
With :contains
, the element will be selected if the string is present directly inside it, or if it is present inside one of its descendants.
$('p:contains("text")');
Get and color red all li
that contain the text 'text'
.