jQuery Multiple Attribute Selector

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

What Is the Multiple Attribute Selector?

The multiple attribute selector (since jQuery 1.0) matches elements that pass every chained attribute filter — [filter1][filter2][filterN]. It is standard CSS with AND logic.

Remember
// Official pattern — has id AND name ends with "man"
$("input[id][name$='man']");

// Mix operators
$("a[href^='https'][target='_blank']");
$("input[type='text'][required]");

// Not OR — use a comma for OR
$("input[id], input[name$='man']");
NeedUse
All filters (AND)$("input[id][name$='man']")
Any filter (OR)$("input[id], input[name$='man']")
Has attribute$("[id]")
Ends with$("[name$='man']")
Equals$("[type='text']")

How to Use Multiple Attribute Filters

Chain attribute brackets after an optional tag, then act on the match.

  1. Start with a tag if helpful: input, a, button.
  2. Add the first filter: [id] or [type='text'].
  3. Chain more filters with no space: [name$='man'].
  4. Every filter must pass — think AND.
  5. Chain methods — .val(), .text(), .addClass().
PieceRequired?Role
TagOptionalLimits which elements are tested
First [filter]YesFirst attribute condition
More [filter]sYes (for “multiple”)Extra AND conditions

Pseudocode

Pseudocode
for each element matching the tag (e.g. input):
    if it fails filter1 → skip
    if it fails filter2 → skip
    …
    if it passes every filter:
        include it in the result

chained brackets = AND
comma-separated selectors = OR

Cheat Sheet

Keep these facts handy while chaining attribute filters.

TopicDetail
Syntax$("[f1][f2][fN]")
SincejQuery 1.0
LogicAND (all filters must match)
CSS?Yes — standard CSS
Mix operators= ^= $= *= presence
vs comma listAND vs OR
Official demo$("input[id][name$='man']")

Live Preview

Run the official AND filter, compare with a single filter, or count matches.

Sample inputs below. AND needs both an id and a name ending in man.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

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

Set a value only when both filters pass (official demo idea, CSS-free).

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

How It Works

  1. Presence. [id] requires an id attribute.
  2. Suffix. [name$='man'] requires the name to end with man.
  3. AND. Both must be true for the same input.
  4. Action. Matching inputs get .val("only this one").

Example 2 — Chaining Narrows the Set

One filter matches more; two filters match fewer.

jQuery
$("#out").text(
  "[name$='man'] → " + $("input[name$='man']").length +
  " | [id][name$='man'] → " + $("input[id][name$='man']").length
);
Try It Yourself

How It Works

  1. Single. Suffix alone includes the input without an id.
  2. Chain. Adding [id] drops that input.
  3. Count. 3 → 2 shows the AND narrowing.
  4. Use. Add filters when one condition is too broad.

Example 3 — Mix Equals and Presence

Combine type equals with a required attribute.

jQuery
$("input[type='text'][required]").val(function (i, v) {
  return v + " *";
});
Try It Yourself

How It Works

  1. Equals. [type='text'] keeps text inputs only.
  2. Presence. [required] needs the attribute present.
  3. AND. Checkbox with required does not match.
  4. Mark. Matching values get a trailing *.

Example 5 — Chain vs Double .filter()

Same AND result — one selector string vs two filter passes.

jQuery
$("#out").text(
  "chain → " + $("input[id][name$='man']").length +
  " | filter → " + $("input").filter("[name$='man']").filter("[id]").length
);
Try It Yourself

How It Works

  1. Chain. One selector evaluates both filters together.
  2. Filter. Two .filter() calls narrow step by step.
  3. Same. Counts match for the same markup.
  4. Prefer. Chained brackets are usually clearer for static AND rules.

Edge Cases & Pitfalls

Check these when a chained attribute selector returns nothing.

logic

AND is strict

Failing any one filter excludes the element. Do not expect OR from adjacent brackets.

space

No space between brackets

[id][name$='man'] chains filters. A space can change the meaning to a descendant search.

case

Value compares are case-sensitive

[name$='man'] does not match name="BatMan" when the casing differs.

quotes

Quote attribute values

Prefer [name$='man'] or double quotes so special characters in values stay safe.

Browser Support

Chained attribute selectors are standard CSS. jQuery has supported them since 1.0. Modern browsers can run them through native querySelectorAll.

✓ Stable · jQuery 1.0+

jQuery [f1][f2]

Works in every browser that runs your loaded jQuery version. Behavior matches CSS attribute filter chaining.

100% 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
Multiple attr Universal

Bottom line: Safe for everyday UI. Chain filters for AND; use a comma-separated list when you need OR.

Performance Notes

ApproachCostBest for
Tagged chain $("input[id][name$='man']")CheapForms and local widgets
Bare chain $("[id][name$='man']")Cheap–moderatePage-wide attribute AND
Double .filter()ModerateDynamic narrowing on an existing set

Prefer a tag plus chained filters so the browser can narrow early. Chained CSS often beats multiple filter passes.

Key Takeaways

  • Role: match elements that pass every chained attribute filter.
  • Logic: adjacent brackets mean AND, not OR.
  • Mix: combine presence, =, ^=, $=, and *=.
  • Scope: prefer a tag like input[…] over a bare page-wide chain.

One line: [a][b] means both attribute filters must match — use a comma list when you need OR.

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 a comma-separated multiple selector for OR.
Yes. You can combine presence ([id]), exact match ([type="text"]), prefix ([href^="https"]), suffix ([name$="man"]), and contains ([class*="btn"]) in one selector string.
Yes. Chained attribute selectors are standard CSS and have worked in jQuery since 1.0. Modern browsers can run them through native querySelectorAll.
Chaining in the selector string ([a][b]) evaluates all filters in one query — often clearer. $("input").filter("[name$=man]").filter("[id]") achieves similar AND narrowing but as separate passes.
Each bracket narrows the result. A single [name$="man"] may match many inputs; adding [id] restricts to elements that also have an id — more specific, fewer false positives.

Next: Has attribute selector

Select elements that simply have a given attribute.

[name] 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.

8 people found this page helpful