77 of 119 menu

Selector contains

The :contains selector selects elements that contain the given text.

Syntax

This is how we select elements by the given text. The text can be in quotes or without. This parameter is also case-sensitive:

$(':contains(text)');

Example

Let's select a paragraph with the text bbb, and put the text '!!!' at the end of it:

<p>aaa</p> <p>bbb</p> <p>ccc</p> $('p:contains("bbb")').append('!!!');

HTML the code will look like this:

<p>aaa</p> <p>bbb!!!</p> <p>ccc</p>

See also

  • method find,
    which searches for elements within those already found
  • method text,
    which gets and changes the text of an element
  • method contents,
    which allows you to get the descendants of an element and the text inside that element
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