jQuery Multiple Attribute Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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.

Syntax

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

jQuery
// 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']");
CallWhat it does
Multiple AttributeLearn jQuery multiple attribute selectors: chain [attr1][attr2] filters with AND logic, use the official input[id][name$='man'] pattern, and mix =, ^=, $=, and presence filters.

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

Parameters

ParameterDescription
Step 1Start with a tag if helpful: input, a, button.
Step 2Add the first filter: [id] or [type='text'].
Step 3Chain more filters with no space: [name$='man'].

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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.

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: Attributes Methods

Select elements that simply have a given attribute.

Attributes Methods 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.

8 people found this page helpful