:contains()S2C Home « Selectors « :contains()

Containing text selector.

Shorthand version $(':contains(text)')


The :contains() selector, selects all elements containing the specified text.

The text can appear in the specified element and/or descendants thereof.

If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.


Signature Description
jQuery(':contains(text)')Text match


Parameter Description
textThe text to search for.



:contains() ExampleTop

Selects all elements containing the specified text.

The following example will check for the text 'the' in 'em' elements and apply an orange background when the button below is clicked.

  $('#btn17').on('click', function() {
    $("em:contains('the')").css('backgroundColor', 'orange');

Press the button below to action the above code: