The attribute contains word selector matches elements whose attribute is a space-separated list, and at least one word exactly equals the search string. Available since jQuery 1.0 (standard CSS).
Remember
$("[attribute~='value']")
$("input[name~='man']")
✓ name="man"
✓ name="milk man"
✗ name="human" (one word — not "man")
✗ name="woman"
~= ≠ *= // *= also matches "human"
[class~='btn'] ≈ .btn // same token idea for class
Use it when the attribute holds space-separated tokens and you need one exact word.
Confirm the attribute is a whitespace-separated list (class, rel, multi-word name, …).
Write $("[attr~='word']") — or with a tag: $("input[name~='man']").
Remember: the word must match a full token, not part of a longer token.
For a plain substring anywhere, use *= instead.
Piece
Required?
Role
attribute
Yes
Attribute that holds space-separated words
value
Yes
One whole word to match exactly
Quotes around value
Recommended
Required for many values; identifiers may omit them
Pseudocode
Pseudocode
attrName = given attribute
word = given value
matches = empty list
for each element with attrName:
tokens = split(attribute value, by whitespace)
if word is exactly equal to any token:
add element
return jQuery(matches)
Reference
Cheat Sheet
Keep these facts handy while matching space-separated words.
Topic
Detail
Syntax
$("[attr~='value']")
Matches
Exact word in a space-separated list
Classic use
$("input[name~='man']")
vs *=
*= = substring anywhere
vs |=
|= = exact or hyphen prefix
Class shortcut
.token ≈ [class~='token']
Since
jQuery 1.0 (standard CSS)
Try it
Live Preview
Compare word / substring / equals selectors against sample inputs and see which name values match.
Sample markup mirrors the official jQuery name~='man' demo, plus class tokens.
active
inactive
Result
$("input[name~='man']")
matched: 2
names: man, milk man
/* whole word only */
Code
jQuery Examples
Short, copy-ready snippets. Open a browser with jQuery loaded, or use Try It Yourself for a live editor.
Example 1 — Official Demo: input[name~="man"]
Find inputs whose name contains the whole word man, then set a new value.
jQuery
$("input[name~='man']").val("mr. man is in it!");
var names = $("input[name~='man']").map(function () {
return this.name;
}).get().join(", ");
console.log(names);
// man, milk man
man, milk man
(human / woman skipped; matched values updated)
How It Works
Limit to inputs. The input tag keeps the search on form controls.
Split on spaces. Each name is treated as a list of words.
Exact token. Only lists that include the word man match.
Update values..val() runs on that whole-word match set.
Example 2 — ~= vs *=
See why human matches substring search but not whole-word search.
jQuery
console.log("~= :", $("input[name~='man']").length);
console.log("*= :", $("input[name*='man']").length);
// ~= skips "human" and "woman"
// *= includes them because "man" appears inside
Multi-value rel. Values like nofollow sponsored are word lists.
Token match.~='nofollow' finds that exact word in the list.
Collect hrefs. Mapping shows which links matched.
Practical use. Filter SEO-related link relationships without substring accidents.
Example 5 — Single-Word Attributes Still Work
A value with no spaces is one token — it matches if that token equals the search word.
jQuery
console.log("role~=button:", $("[role~='button']").length);
console.log("role=button :", $("[role='button']").length);
// For a single token, ~= and = often return the same element
role~=button: 1
role=button : 1
Both match role="button"
How It Works
One token list.role="button" splits to ["button"].
Exact equality. That single token equals button, so ~= matches.
Same as = here. With no extra words, = and ~= agree.
When they differ. Add more space-separated tokens and only ~= stays flexible.
Edge Cases & Pitfalls
Check these before relying on ~= in real projects.
trap
~= ≠ *=
[name~="man"] skips human. [name*="man"] includes it. Use whole-word matching when tokens matter.
spaces
Only whitespace delimits words
Hyphens and underscores do not split tokens. milk-man is one word, not milk + man.
class
Prefer .class for classes
[class~="btn"] works, but $(".btn") is clearer and the usual choice for class tokens.
case
Case-sensitive tokens
In HTML, [rel~="nofollow"] does not match rel="NoFollow". Keep casing consistent.
Compatibility
Browser Support
The attribute contains word selector [attr~="value"] is standard CSS and has worked in jQuery since 1.0. Modern browsers implement it in native querySelectorAll.
✓ CSS · jQuery 1.0+
jQuery [name~="value"]
Supported in all modern browsers. Native: document.querySelectorAll("input[name~='man']"). Exact word match in space-separated lists.
100%Standard CSS selector
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
~= combinatorUniversal
Bottom line: Safe everywhere jQuery runs. Use for token lists (class, rel, multi-word names); switch to *= only when you truly want a substring.
Analysis
Performance Notes
Approach
Cost
Best for
$(".active")
Fastest for classes
Class tokens
$("input[name~='man']")
Native-friendly CSS
Scoped form controls
$("[rel~='nofollow']")
Wider scan
Any element with that rel token
Attribute selectors are standard CSS, so jQuery can often use the browser engine. For classes, prefer .token. Narrow with a tag or container on large pages.
Remember
Key Takeaways
Role: match an exact word in a space-separated attribute list.
Classic use:$("input[name~='man']") from the official demo.
Not *=:human matches *=, not ~=.
Classes: prefer .token; use ~= for rel and similar lists.
One line: use [attr~="value"] when you need an exact space-delimited word — not a loose substring.
Frequently Asked Questions
It selects elements whose named attribute is a space-separated list of words, where at least one word exactly equals the search string. For example, [class~="active"] matches class="btn active primary" because active is a whole word.
[attr*="man"] matches if "man" appears anywhere — including inside "human". [attr~="man"] matches only when "man" is its own whitespace-delimited word, such as name="mr man".
CSS defines a word as a string delimited by whitespace. The attribute value is split on spaces; each token must exactly equal the search string to match.
Almost — both match elements with btn as a class token. The class selector .btn is shorter for styling. [class~="btn"] is useful when you need the same token logic on non-class attributes like rel or role.
Yes. The attribute contains word selector is standard CSS and has worked in jQuery since 1.0, with native querySelectorAll support in modern browsers.
No. "human" is a single word, not a list containing the separate word "man". That is the key difference from [name*="man"], which would match "human".