:contains(text) (since jQuery 1.1.4) selects elements whose text content includes the given string. The text may sit on the element itself, in any descendant, or both. Matching is case-sensitive. Quotes around the text are optional.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("div:contains('John')") // text includes "John"
$("div:contains(John)") // same — quotes optional
$(":contains('John')") // avoid — scans every element
// Case-sensitive: "john" ≠ "John"
// Prefer a tag or parent: $("#list li:contains('apple')")
Call
What it does
:contains()
Learn the jQuery :contains() selector: find elements by text content, case-sensitive substring rules, text in descendants, official John demo, pitfalls, browser support, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Start with a tag or scoped selector: $("div:contains('…')") or $("#box p:contains('…')").
Step 2
Pass the search string — with or without quotes; casing must match.
Step 3
Remember parents match when a child holds the text (aggregated text content).
Return Value
Return Value
Description
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
Parent.#card:contains('Sale') still matches the card.
Child. You can also target the span directly.
Frequently Asked Questions
:contains(text) selects every element whose text content includes the given string — as direct text, inside descendants, or both. $("div:contains('John')") matches a div showing "John Resig" or "Malcom John Sinclair" because "John" appears in that element’s aggregated text.
Yes. Official jQuery docs state the search is case-sensitive. :contains("john") does not match "John Resig". Match the exact casing you expect in the DOM.
Yes. The matching text can appear directly in the element, in any descendant, or a combination. A parent div matches when a nested span holds the search string.
:contains() searches element text content. [name*="value"] searches HTML attribute values such as href or title — not rendered text. Use the right tool for text vs attributes.
No. :contains() is a jQuery extension — not valid CSS. It works inside $() / Sizzle only. document.querySelectorAll(":contains('John')") throws a syntax error.
Prefer scoping: $("#list li:contains('apple')") or $("div.item").filter(":contains('sale')"). Bare $(":contains(text)") scans every element and can be slow on large pages.