⊗jqBsPCHa 25 of 113 menu

Pseudo-class :has in jQuery

Pseudo-class has selects elements by their content. Let's look at an example. Let's say we have the following HTML code:

<p>text with <b>b</b> tag</p> <p>text with <i><b>b</b></i> tag</p> <p>text</p>

For example, let's select all paragraphs that contain the tags b:

$('p:has(b)');

Note that in the example both the first paragraph and the second will be selected, despite the fact that in the second paragraph the tag b does not lie directly inside p, but lies first in i.

If you need direct nesting, you should do it like this:

$('p:has(>b)');

In this case, only the first paragraph will be selected.

Get and color red all h2 that contain the tag i inside.

Get and color red all h2 that directly contain the tag i.

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