76 of 119 menu

Selector has

The :has selector selects elements that contain at least one element matching the given selector, not necessarily an immediate descendant. Since :has is not part of the CSS specification, for better performance in modern browsers it is better to use $("your css selector").has(selector/DOM ​​element) instead.

Syntax

This is how we select elements:

$(':has(selector)');

This is how we select elements if we need direct nesting of the selector:

$(':has(>selector)');

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 has,
    which filters the set of selected elements by descendants
  • method filter,
    which filters elements in a set by a given selector
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