jQuery Attribute Contains [name*="value"]

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is [name*="value"]?

The attribute contains selector matches elements whose attribute value includes a given substring anywhere — start, middle, or end. Available since jQuery 1.0 (standard CSS3).

Remember
$("[attribute*='value']")

$("input[name*='man']")
  ✓ name="man"
  ✓ name="human"
  ✓ name="woman"
  ✗ name="person"     (no "man" substring)

*=  ≠  ~=   // ~= needs a whole space-separated word
*=  ≠  ^=   // ^= is start only
UsePrefer
Substring anywhere$("[attr*='man']")
Whole word in a list$("[attr~='man']")
Starts with$("[attr^='man']")

How to Use [name*="value"]

Name the attribute, pick a substring, then query — optionally scoped to a tag.

  1. Choose the attribute (name, href, data-id, …).
  2. Write $("[attr*='substring']") — or with a tag: $("input[name*='man']").
  3. Expect matches at any position inside the attribute string.
  4. If you need a whole word in a space list, switch to ~= instead.
PieceRequired?Role
attributeYesAttribute name to search
valueYesSubstring that must appear somewhere
Quotes around valueRecommendedRequired for many values; identifiers may omit them

Pseudocode

Pseudocode
attrName  = given attribute
substring = given value
matches   = empty list

for each element with attrName:
    v = element.getAttribute(attrName)
    if v contains substring:          // anywhere
        add element

return jQuery(matches)

Cheat Sheet

Keep these facts handy while matching attribute substrings.

TopicDetail
Syntax$("[attr*='value']")
MatchesSubstring anywhere in the attribute
Classic use$("input[name*='man']")
vs ~=~= = whole word in a space list
vs ^= / $=Start only / end only
vs == is exact equality
SincejQuery 1.0 (CSS3)

Live Preview

Run substring / word / starts-with selectors against sample inputs and see which name values match.

Sample markup mirrors the official jQuery name*='man' demo, plus a space-list trap.

Result
$("input[name*='man']")
matched: 4
names: man, human, woman, milk man

/* substring anywhere */

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 man, then set a new value (jQuery API example).

jQuery
$("input[name*='man']").val("has man in it!");

var names = $("input[name*='man']").map(function () {
  return this.name;
}).get().join(", ");

console.log(names);
// man, human, woman
Try It Yourself

How It Works

  1. Limit to inputs. The input tag keeps the search on form controls.
  2. Apply *=. Any name that contains man matches.
  3. Set values. .val() updates every match in one call.
  4. List names. Mapping this.name shows which controls were selected.

Example 2 — *= vs ~=

See why a space-separated list behaves differently for substring vs whole-word matching.

jQuery
console.log("*= :", $("input[name*='man']").length);
console.log("~= :", $("input[name~='man']").length);

// *= matches "human", "woman", and "milk man"
// ~= matches only names where "man" is a whole word ("man", "milk man")
Try It Yourself

How It Works

  1. Substring rule. *= finds man inside longer tokens like human.
  2. Word rule. ~= splits on spaces and looks for the exact word man.
  3. Compare counts. Lengths show how much wider *= is.
  4. Official tip. For list-like attributes, ~= is often more precise.

Example 3 — Match Links by href Substring

Select anchors whose URL contains a path fragment.

jQuery
var hrefs = $("a[href*='/docs/']").map(function () {
  return $(this).attr("href");
}).get().join(", ");

console.log(hrefs);
Try It Yourself

How It Works

  1. Target anchors. a[href*=…] only considers links.
  2. Look inside the URL. The substring can sit in the middle of the path.
  3. Collect hrefs. Mapping prints every matching URL.
  4. Practical use. Highlight doc links without listing every full path.

Example 4 — data-id Contains a Token

Find elements whose custom data attribute includes a shared fragment.

jQuery
var ids = $("[data-id*='user']").map(function () {
  return $(this).attr("data-id");
}).get().join(", ");

console.log(ids);
// user-1, guest-user, user
Try It Yourself

How It Works

  1. Any element. Omitting a tag searches every node with data-id.
  2. Shared fragment. user matches at the start, middle, or alone.
  3. Skip unrelated. Values without that substring are ignored.
  4. Tip. Prefer a stricter operator if the fragment appears in unwanted places.

Example 5 — Case Sensitivity

Attribute value matching is case-sensitive — casing must align.

jQuery
console.log("man :", $("input[name*='man']").length);
console.log("Man :", $("input[name*='Man']").length);

// name="Man" matches only the second query
Try It Yourself

How It Works

  1. Same letters, different case. Selectors compare the string as written.
  2. Lowercase query. Matches lowercase name values that contain man.
  3. Capitalized query. Matches only values that contain Man.
  4. Habit. Keep attribute values and selectors in a consistent casing style.

Edge Cases & Pitfalls

Check these before relying on *= in real projects.

broad

Over-matching is easy

[name*="man"] also hits human and woman. Prefer ~=, ^=, or $= when you need stricter rules.

word

*= ≠ ~=

For space-separated lists (class-like tokens), ~= matches whole words only. Official docs call ~= more appropriate in many cases.

case

Case-sensitive values

In HTML, [name*="man"] does not match name="Man". Align casing in markup and selectors.

empty

Empty substring is a trap

[attr*=""] can match every element that has that attribute. Avoid empty search strings.

Browser Support

The attribute contains selector [attr*="value"] is part of CSS3 and has worked in jQuery since 1.0. Modern browsers implement it in native querySelectorAll.

✓ CSS3 · jQuery 1.0+

jQuery [name*="value"]

Supported in all modern browsers. Native: document.querySelectorAll("input[name*='man']"). Most generous attribute value matcher.

100% Standard CSS selector
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
*= combinator Universal

Bottom line: Safe everywhere jQuery runs. Use for flexible substring matches; switch to ~= when you need a whole word in a space-separated list.

Performance Notes

ApproachCostBest for
$("input[name*='man']")Native-friendly CSSScoped form controls
$("[data-id*='user']")Wider scanAny element with that data attr
$("[class*='btn']")Often too broadPrefer .btn or ~=

Attribute selectors are standard CSS, so jQuery can often use the browser engine. Narrow with a tag or a container on large pages, and avoid *= on class when a real class selector would do.

Key Takeaways

  • Role: match if the attribute value contains a substring anywhere.
  • Classic use: $("input[name*='man']") from the official demo.
  • Not ~=: for whole words in space lists, prefer ~=.
  • Standard CSS: works in jQuery 1.0+ and native querySelectorAll.

One line: use [attr*="value"] for flexible substring matches — and tighten with ~= when you need a whole word.

Frequently Asked Questions

It selects every element whose named attribute value contains the given substring anywhere — start, middle, or end. For example, [name*="man"] matches name="human", name="woman", and name="man".
Yes. Among jQuery attribute selectors that compare against a value, *= is the most generous — the substring can appear at any position inside the attribute string.
[attr*="man"] matches if "man" appears anywhere in the value. [attr~="man"] matches only when "man" is a whole space-separated word. For class-like lists, ~= is often more precise.
Yes. The attribute contains selector has worked in jQuery since 1.0 and is part of standard CSS3 attribute selectors supported by modern browsers.
In HTML documents, attribute selector matching is generally case-sensitive for attribute values. name="Man" does not match [name*="man"] unless the casing aligns.
Yes. The official demo uses $("input[name*=\"man\"]") to target only input elements whose name attribute contains the substring man.

Next: [name~="value"]

Match a whole word inside a space-separated attribute list.

~= selector tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful