jQuery Attribute Contains [name*="value"]

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Substring match

What You’ll Learn

The attribute contains selector — written [name*="value"] — matches elements whose attribute value includes a substring anywhere inside it. It is the most flexible value-matching attribute selector in jQuery and has been available since version 1.0.

01

Syntax

[attr*="x"]

02

Anywhere

Start/mid/end

03

Official

name*=man

04

vs ~=

Word vs substring

05

Forms

Input names

06

Since 1.0

CSS3 + jQuery

Introduction

Attribute selectors let you target HTML elements by their metadata — not just tag names or classes. The contains form uses an asterisk equals sign (*=) and answers a simple question: “Does this attribute value include this text anywhere?”

jQuery documents it as the most generous attribute selector when matching against a value. That flexibility makes it ideal for partial matches — form field names that share a prefix, URLs that contain a domain fragment, or file extensions embedded in a href. It has worked in jQuery since 1.0 and maps to standard CSS3 syntax browsers understand natively.

Understanding the Contains Selector

Given [attribute*="needle"], jQuery selects an element when the string needle appears as a contiguous substring inside the attribute’s value. Position does not matter:

  • Startname="manual" contains man.
  • Middlename="human" contains man.
  • Endname="superman" contains man.

The element must actually have the attribute present. An input without a name attribute is never matched by [name*="…"].

💡
Beginner Tip

For space-separated token lists like class="btn primary", prefer [class~="primary"] (contains word) when you need whole-word matching — *= would also match primary-btn.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( "[attribute*='value']" )
// shorthand:
$( "[attribute*='value']" )

// combine with element types:
$( "input[name*='man']" )

Parameters

  • attribute — the HTML attribute name (e.g. name, href, class).
  • value — substring to search for inside the attribute value; quote if it contains special characters.

Return value

  • A jQuery object with every element whose attribute contains the substring.
  • Empty collection when no values match.

Official jQuery API example

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

// Sets value on inputs whose name contains "man"
// e.g. name="human", name="woman", name="superman"

⚡ Quick Reference

name value[name*="man"]
humanMatches (middle)
womanMatches (end)
manualMatches (start)
supermanMatches
childNo match
(no name attr)No match

📋 [attr*="man"] vs Other Attribute Operators

Five CSS attribute operators — pick the one that matches your intent, not just the loosest option.

Contains *
[attr*="man"]

Substring anywhere

Word ~
[attr~="man"]

Whole space-separated word

Starts ^
[attr^="man"]

Value begins with man

Exact =
[attr="man"]

Full value equals man

Examples Gallery

Example 1 follows the official jQuery API demo. Examples 2–5 explore substring rules, operator comparisons, link filtering, and scoped form fields. Use the Try-it links to run each snippet in the browser.

📚 Official jQuery Demo

Set the value on inputs whose name contains man.

Example 1 — Official Demo: input[name*='man']

Find every input whose name attribute contains the substring man, then set a message with .val().

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

// Matches name="human", name="woman", name="superman"
// Skips name="child" and inputs without a name attribute
Try It Yourself

How It Works

jQuery scans each input’s name attribute for the contiguous substring man. The match succeeds regardless of where those three letters appear in the value.

Example 2 — Substring Match at Start, Middle, and End

Test several name values programmatically to see which qualify.

jQuery
var names = [ "manual", "human", "woman", "superman", "child" ];

names.forEach( function( n ) {
  var $input = $( "<input>" ).attr( "name", n ).appendTo( "body" );
  console.log( n, "→", $input.is( "[name*='man']" ) ? "MATCH" : "no" );
  $input.remove();
});
Try It Yourself

How It Works

.is("[name*='man']") returns true whenever man appears as a substring — even inside longer words like superman.

📈 Practical Patterns

Operator comparisons, link filtering, and scoped queries.

Example 3 — [class*="btn"] vs [class~="btn"]

See why the docs recommend the word selector for token lists — *= is broader than you might want on classes.

jQuery
$( "#samples span" ).each( function() {
  var $el = $( this );
  console.log(
    $el.attr( "class" ),
    "| *:", $el.is( "[class*='btn']" ),
    "| ~:", $el.is( "[class~='btn']" )
  );
});
Try It Yourself

How It Works

*= finds the letters btn anywhere — including inside toolbar. ~= requires btn to be a whole space-separated token.

Example 4 — Filter Links with a[href*='.pdf']

Highlight download links whose URL contains a PDF extension anywhere in the path.

jQuery
$( "a[href*='.pdf']" ).addClass( "pdf-link" );

// Matches /docs/guide.pdf and /files/report.PDF only if case matches
// Does not match plain /about page links
Try It Yourself

How It Works

The substring .pdf can appear anywhere in the URL string — filename, query parameter, or path segment — as long as those characters appear contiguously.

Example 5 — Scoped Form Fields #signup input[name*='email']

Target email-related inputs inside one form without affecting other forms on the page.

jQuery
$( "#signup input[name*='email']" ).addClass( "email-field" );

// Matches name="email", name="billing_email", name="confirm_email"
// Only inside #signup — login form fields ignored
Try It Yourself

How It Works

Combining a form ID, element type, and *= attribute filter keeps the query fast and explicit — a common pattern for multi-field registration forms.

🚀 Common Use Cases

  • Form field groupsinput[name*='address'] for every address-related input.
  • File type linksa[href*='.pdf'] or a[href*='download'].
  • CDN assetsscript[src*='cdn.example.com'] for third-party scripts.
  • Data attributes[data-role*='admin'] for partial role keys.
  • Icon fontsi[class*='fa-'] when class names share a prefix fragment.
  • Migration helpers — find legacy IDs with [id*='old_'] during refactors.

🧠 How jQuery Evaluates [attr*="value"]

1

Collect candidates

jQuery gathers elements matching the CSS portion of your selector (tag, ID, class).

Query
2

Read attribute

For each candidate, read the named attribute’s string value.

DOM
3

Substring search

If the search string appears anywhere inside the value, the element matches.

Contains
4

Return collection

All matches become a jQuery object for chaining .val(), .addClass(), etc.

📝 Notes

  • Available since jQuery 1.0 — standard CSS3 attribute selector.
  • Most generous jQuery attribute selector when matching against a value (per official docs).
  • For space-separated token attributes like class, consider [attr~="word"] instead.
  • Matching is case-sensitive in typical HTML documents.
  • Missing attributes never match — the element is skipped entirely.
  • Very short substrings (e.g. *="a") may over-match; prefer specific needles.

Browser Support

The attribute contains selector is part of CSS3 and works in jQuery 1.0+. Evergreen browsers accelerate it through native querySelectorAll — use specific element prefixes like input[name*='…'] for best performance.

CSS3 · jQuery 1.0+

jQuery [attribute*="value"]

Supported in all modern browsers and IE7+ for attribute selectors. Native: document.querySelectorAll("input[name*='man']").

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
[attr*="value"] Universal

Bottom line: Safe for production partial matching on names, hrefs, and data attributes. Prefer [attr~="word"] for class lists when you need whole-token matching.

Conclusion

The attribute contains selector [name*="value"] matches when a substring appears anywhere inside an attribute value. jQuery’s official demo — $("input[name*='man']").val("has man in it!") — shows the pattern on form fields.

Use it when you need flexible partial matching. When you care about whole words in token lists, switch to [attr~="word"]. When you need prefix or exact rules, reach for ^=, |=, or = instead.

💡 Best Practices

✅ Do

  • Use input[name*='email'] for related form field names
  • Combine with IDs or forms: $("#signup input[name*='…']")
  • Pick specific substrings to avoid accidental matches
  • Use [class~="token"] for whole class names
  • Quote values with special CSS characters

❌ Don’t

  • Use *= on class when you mean a whole class token
  • Rely on one-letter substrings — they match too broadly
  • Assume case-insensitive matching in HTML
  • Expect matches on elements missing the attribute
  • Confuse *= (contains) with ^= (starts with)

Key Takeaways

Knowledge Unlocked

Five things to remember about [attr*="value"]

Substring match anywhere in the value.

5
Core concepts
02

Anywhere

Start/mid/end

Flexible
man 03

Official

name*=man

Demo
~ 04

vs ~=

Word token

Compare
📄 05

Forms

Field groups

Use case

❓ 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="superman".
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 in a list-like attribute (e.g. class="btn man primary"). For class 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.
Did you know?

jQuery’s official docs call [attribute*="value"] the most generous attribute selector for value matching — but also note that [attr~="word"] (contains word) is often more appropriate for space-separated lists like class.

Continue to [attr~=value]

Learn whole-word matching for space-separated attribute values like class.

Attribute word 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.

6 people found this page helpful