61 of 119 menu

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>

See also

  • method filter,
    which filters elements in a set by a given selector
  • method find,
    which searches for elements within those already found
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline