jQuery Attribute Contains [name*="value"]

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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).

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("[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
CallWhat it does
See the examples below.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Choose the attribute (name, href, data-id, …).
Step 2Write $("[attr*='substring']") — or with a tag: $("input[name*='man']").
Step 3Expect matches at any position inside the attribute string.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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.

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: Attribute Contains Word Selector

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

Attribute Contains Word Selector tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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