jQuery Multiple Attribute [name="value"][name2="value2"]

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

What You’ll Learn

The multiple attribute selector — written [filter1][filter2][filterN] — matches elements that satisfy every chained attribute filter. Each bracket narrows the set with AND logic. Combine presence, equals, prefix, suffix, and contains operators in one query — available since jQuery 1.0.

01

Syntax

[a][b][c]

02

AND

All must match

03

Mix

= ^ $ *

04

Official

[id][name$='man']

05

Narrow

More specific

06

Since 1.0

CSS + jQuery

Introduction

Single attribute selectors are powerful on their own — but real pages often need elements that meet several attribute conditions at once. A checkbox named agree, a secure external link, or an email field marked required each needs more than one filter.

Chain attribute selectors back-to-back with no space between brackets: [attributeFilter1][attributeFilter2]. jQuery evaluates every filter and returns only elements that pass all of them. This pattern is standard CSS and has worked in jQuery since version 1.0.

Understanding Multiple Attribute Selectors

Think of each bracket as a gate. An element must pass through every gate to be selected. If it fails any single filter, it is excluded — even if it matched the others.

  • name="newsletter", has id[id][name$="letter"] matches.
  • name="newsletter", no id[id][name$="letter"] does not match (missing id).
  • type="checkbox", name="agree"[type="checkbox"][name="agree"] matches.
  • type="checkbox", name="subscribe"[type="checkbox"][name="agree"] does not match.
💡
Beginner Tip

Order of brackets does not change AND logic — [id][name$="man"] and [name$="man"][id] select the same elements. Put the filter that eliminates the most candidates first when scoping for readability.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( "[attributeFilter1][attributeFilter2][attributeFilterN]" )
// shorthand:
$( "[attributeFilter1][attributeFilter2][attributeFilterN]" )

// common patterns:
$( "input[id][name$='man']" )
$( "a[href^='https'][target='_blank']" )
$( "input[type='checkbox'][name='agree']" )

Parameters

  • attributeFilter1…N — any valid CSS attribute selector: presence ([name]), exact ([type="text"]), prefix ([href^="https"]), suffix ([name$="pdf"]), contains ([class*="btn"]), etc.
  • Chaining — no space or comma between brackets; each additional filter applies AND logic.

Return value

  • A jQuery object containing every element that satisfies all specified attribute filters.
  • Empty collection when no element passes every filter.

Official jQuery API example

jQuery
$( "input[id][name$='man']" ).val( "only this one" );

// Matches inputs that HAVE an id attribute
// AND whose name value ENDS WITH "man"
// Skips inputs with name ending in "man" but no id

⚡ Quick Reference

Element[id][name$="man"]
<input id="a" name="superman">Matches
<input name="superman"> (no id)No match
<input id="b" name="manual">No match (name does not end with man)
<input id="c" name="Batman">No match (case-sensitive suffix)
<input id="d" name="postman">Matches
<span id="e" name="man">No match (not an input — add tag if needed)

📋 Chaining vs .filter(), AND vs OR

Multiple brackets mean AND. Commas and repeated .filter() calls behave differently.

Chained AND
input[id][name$="man"]

All filters in one query

.filter() AND
$("input").filter("[id]").filter("[name$='man']")

Same narrowing, two passes

Comma OR
input[id], input[name$="man"]

Either filter — not both

Mix operators
a[href^="https"][target="_blank"]

Presence + = + ^ + $ + *

Examples Gallery

Example 1 follows the official jQuery API demo. Examples 2–5 cover checkbox fields, secure external links, single vs chained narrowing, and scoped form queries. Use the Try-it links to run each snippet.

📚 Official jQuery Demo

Set the value on inputs that have an id and whose name ends with man.

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

Official jQuery demo — find inputs with an id attribute AND name ending with man, then set their value.

jQuery
$( "input[id][name$='man']" ).val( "only this one" );

// Matches: <input id="hero" name="superman">
// Skips: <input name="superman"> (no id)
// Skips: <input id="x" name="manual"> (name does not end with man)
Try It Yourself

How It Works

Both [id] (presence) and [name$='man'] (suffix) must pass. Removing either bracket widens the match — that is the power of chained AND logic.

Example 2 — Checkbox with Exact Type and Name

Target the terms agreement checkbox using exact type and name filters.

jQuery
$( "input[type='checkbox'][name='agree']" ).prop( "checked", true );

// Matches type="checkbox" AND name="agree"
// Skips text inputs named agree or other checkboxes
Try It Yourself

How It Works

Pairing type with name avoids selecting hidden fields or similarly named inputs of a different type — a common form-validation pattern.

📈 Practical Patterns

External links, narrowing comparisons, and scoped multi-filter queries.

Example 3 — Secure External Links

Select anchor tags that open in a new tab and use HTTPS URLs.

jQuery
$( "a[href^='https'][target='_blank']" ).addClass( "external-secure" );

// Matches href starting with https AND target="_blank"
// Skips http links or same-tab https links
Try It Yourself

How It Works

Prefix (^=) and exact (=) operators combine in one selector — no need for separate JavaScript checks when CSS attribute rules suffice.

Example 4 — Single Filter vs Chained AND

Compare how adding [id] narrows a suffix-only selector.

jQuery
var single = $( "input[name$='man']" ).length;
var chained = $( "input[id][name$='man']" ).length;

console.log( "name$='man' only:", single );
console.log( "id AND name$='man':", chained );
console.log( "Chained is more specific → fewer matches" );
Try It Yourself

How It Works

Each chained bracket is an additional requirement. Use multiple filters when a single operator returns too many elements.

Example 5 — Scoped Required Email Field

Highlight the required email input inside a specific signup form.

jQuery
$( "form#signup input[type='email'][required]" ).addClass( "highlight" );

// Matches email type AND required attribute inside #signup
// Ignores optional email fields or emails in other forms
Try It Yourself

How It Works

Combine a form ID with chained attribute filters for precise, readable queries — type, presence (required), and container scope in one line.

🚀 Common Use Cases

  • Form fieldsinput[type='checkbox'][name='agree'], input[type='email'][required].
  • Secure linksa[href^='https'][target='_blank'] for external HTTPS tabs.
  • File inputsinput[type='file'][accept*='image'] combining type and accept.
  • Radio groupsinput[type='radio'][name='size'][value='large'] with three chained filters.
  • Data attributes[data-role='admin'][data-active='true'] for compound state.
  • Narrow suffix matchesinput[id][name$='man'] when suffix alone is too broad.

🧠 How jQuery Evaluates Chained Attribute Selectors

1

Parse chain

Split the selector into element type plus each [filter] bracket.

CSS
2

Test each filter

Every attribute condition must pass — presence, exact, prefix, suffix, or contains.

AND
3

Reject on first fail

One failed filter excludes the element, even if other filters matched.

Strict
4

Return collection

Elements passing all filters become a jQuery object for chaining.

📝 Notes

  • Available since jQuery 1.0 — standard CSS multiple attribute selector.
  • Chained brackets use AND logic — not OR. Use commas for OR.
  • Order of brackets does not change which elements match.
  • Mix any operators: [id], [type="text"], [name$="pdf"], [href^="https"].
  • More filters mean a smaller, more specific result set.
  • Pair with element type and container IDs for performance: form#signup input[type='email'][required].

Browser Support

Multiple attribute selectors are part of CSS and work in jQuery 1.0+. Evergreen browsers support chained filters in native querySelectorAll. IE7+ supports attribute selectors with jQuery fallbacks where needed.

CSS · jQuery 1.0+

jQuery [filter1][filter2]

Supported in all modern browsers. Native: document.querySelectorAll("input[id][name$='man']"). Chained AND logic applies everywhere.

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
[a][b][c] Universal

Bottom line: Ideal when you need elements meeting several attribute conditions. Add brackets to narrow; use commas when you need OR instead.

Conclusion

The multiple attribute selector chains filters with AND logic — [filter1][filter2][filterN] matches only elements that pass every condition. jQuery’s official demo, $("input[id][name$='man']").val("only this one"), shows how presence and suffix filters combine to target one specific input.

Use chaining when a single attribute operator returns too many elements. Mix =, ^=, $=, *=, and presence selectors freely. Remember that commas mean OR, while chained brackets mean AND — scope queries to forms and containers for clarity.

💡 Best Practices

✅ Do

  • Chain filters when you need AND logic: input[type='checkbox'][name='agree']
  • Scope queries: form#signup input[type='email'][required]
  • Mix operators for clarity: a[href^='https'][target='_blank']
  • Add brackets to narrow overly broad single filters
  • Prefer one chained selector over multiple .filter() calls when starting fresh

❌ Don’t

  • Expect OR from chained brackets — use commas instead
  • Confuse input[a][b] (AND) with input[a], input[b] (OR)
  • Chain unnecessarily when one filter is already specific enough
  • Forget that [name] checks presence, not a value
  • Assume order of brackets changes AND results

Key Takeaways

Knowledge Unlocked

Five things to remember about chained attribute selectors

Every bracket must pass — AND logic all the way.

5
Core concepts
[] 02

Mix ops

= ^ $ *

Syntax
id 03

Narrow

More specific

Pattern
≠ , 04

Not OR

Commas differ

Compare
man 05

Official

id + name$ demo

Demo

❓ Frequently Asked Questions

It selects elements that satisfy every chained attribute filter — all conditions must pass. For example, [id][name$="man"] matches only elements that have an id attribute AND whose name value ends with man.
Yes. Writing [filter1][filter2][filter3] means the element must match filter1 AND filter2 AND filter3. There is no OR between chained brackets — use .filter() with multiple selectors or a comma-separated list for OR.
Yes. You can combine presence ([id]), exact match ([type="text"]), prefix ([href^="https"]), suffix ([name$="pdf"]), and contains ([class*="btn"]) in one selector string.
Yes. Multiple attribute selectors are standard CSS and have worked in jQuery since 1.0, with native querySelectorAll support in modern browsers.
Chaining in the selector string ([a][b]) evaluates all filters during the initial query — often faster and clearer. $( "input" ).filter( "[name$=man]" ).filter( "[id]" ) achieves similar AND narrowing on an existing collection but runs as separate passes.
Each bracket narrows the result set. A single [name$="man"] may match many inputs; adding [id] restricts to elements that also have an id — more specific, fewer false positives.
Did you know?

Chaining attribute selectors in jQuery works exactly the same way as in CSS stylesheets. Rules like input[type="checkbox"][disabled] { opacity: 0.5; } use the same AND logic — every bracket must match before the style applies.

Continue to Has Attribute Selector

After chaining multiple filters, revisit attribute presence with [name] — the selector that completes the attribute ring.

Has attribute 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