The has method
The has method filters the set of selected elements, leaving only those that have descendants that match the given selector.
Syntax
Filter by descendants:
.has(descendant selector);
Here's how you can filter a set of selected elements, leaving only the one that contains a given DOM element inside:
.has(DOM element);
Example
Let's select only those paragraphs that have the tag b inside and put the text '!!!' at the end of them:
<p>text</p>
<p>text</p>
<p><b>bold</b> text</p>
<p><b>bold</b> text</p>
$('p').has('b').append('!!!');
HTML the code will look like this:
<p>text</p>
<p>text</p>
<p><b>bold</b> text!!!</p>
<p><b>bold</b> text!!!</p>