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
Fundamentals
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.
Concept
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:
Start — name="manual" contains man.
Middle — name="human" contains man.
End — name="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.
Foundation
📝 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"
Cheat Sheet
⚡ Quick Reference
name value
[name*="man"]
human
Matches (middle)
woman
Matches (end)
manual
Matches (start)
superman
Matches
child
No match
(no name attr)
No match
Compare
📋 [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
Hands-On
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
human, woman, superman inputs → value "has man in it!"
child input and unnamed input → unchanged
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();
});
*= 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
Links to guide.pdf and annual-report.pdf → class "pdf-link"
Regular HTML page links → unchanged
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
Signup email, billing_email, confirm_email → class "email-field"
Same name pattern in #login form → not styled
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.
Applications
🚀 Common Use Cases
Form field groups — input[name*='address'] for every address-related input.
File type links — a[href*='.pdf'] or a[href*='download'].
CDN assets — script[src*='cdn.example.com'] for third-party scripts.
Data attributes — [data-role*='admin'] for partial role keys.
Icon fonts — i[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.
Important
📝 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.
Compatibility
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 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
[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.
Wrap Up
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.
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)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about [attr*="value"]
Substring match anywhere in the value.
5
Core concepts
*01
*= syntax
Contains
API
…02
Anywhere
Start/mid/end
Flexible
man03
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.