jQuery Attribute Ends With [name$="value"]

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

What Is [name$="value"]?

The attribute ends-with selector matches elements whose attribute value ends exactly with a given string (suffix). Available since jQuery 1.0 (standard CSS3).

Remember
$("[attribute$='value']")

$("input[name$='letter']")
  ✓ name="newsletter"
  ✓ name="loveletter"
  ✗ name="letterbox"    (ends with "box")
  ✗ name="myLetter"     (case differs)

$=  ≠  ^=   // ^= is start only
$=  ≠  *=   // *= is anywhere
UsePrefer
Suffix match$("[attr$='letter']")
Prefix match$("[attr^='letter']")
Anywhere$("[attr*='letter']")

How to Use [name$="value"]

Name the attribute, pick a suffix, then query — casing must match exactly.

  1. Choose the attribute (name, href, id, …).
  2. Write $("[attr$='suffix']") — or with a tag: $("input[name$='letter']").
  3. Confirm the value truly ends with that string (not just contains it).
  4. Watch case: .pdf and .PDF are different suffixes.
PieceRequired?Role
attributeYesAttribute name to test
valueYesExact suffix the value must end with
Quotes around valueRecommendedRequired for many values; identifiers may omit them

Pseudocode

Pseudocode
attrName = given attribute
suffix   = given value
matches  = empty list

for each element with attrName:
    v = element.getAttribute(attrName)
    if v ends with suffix:            // case-sensitive
        add element

return jQuery(matches)

Cheat Sheet

Keep these facts handy while matching attribute suffixes.

TopicDetail
Syntax$("[attr$='value']")
MatchesValue ending exactly with the suffix
Classic use$("input[name$='letter']")
File links$("a[href$='.pdf']")
CaseSensitive (.pdf ≠ .PDF)
vs ^= / *=Start only / anywhere
SincejQuery 1.0 (CSS3)

Live Preview

Run ends-with / starts-with / contains selectors against sample inputs and see which name values match.

Sample markup mirrors the official jQuery name$='letter' demo, plus file-link examples.

Result
$("input[name$='letter']")
matched: 2
names: newsletter, loveletter

/* ends exactly with letter */

jQuery Examples

Short, copy-ready snippets. Open a browser with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: input[name$="letter"]

Find inputs whose name ends with letter, then set a new value.

jQuery
$("input[name$='letter']").val("a letter");

var names = $("input[name$='letter']").map(function () {
  return this.name;
}).get().join(", ");

console.log(names);
// newsletter, loveletter
Try It Yourself

How It Works

  1. Limit to inputs. The input tag keeps the search on form controls.
  2. Apply $=. Only names that end with letter match.
  3. Skip mid-word hits. letterbox contains letter but does not end with it.
  4. Set values. .val() updates every suffix match in one call.

Example 2 — $= vs ^=

Contrast ending with letter against starting with letter.

jQuery
console.log("$= :", $("input[name$='letter']").length);
console.log("^= :", $("input[name^='letter']").length);

// $= matches newsletter, loveletter
// ^= matches letterbox (starts with letter)
Try It Yourself

How It Works

  1. Suffix rule. $= looks only at the end of the value.
  2. Prefix rule. ^= looks only at the start.
  3. Same fragment, different place. letter can sit at either end.
  4. Pick the end that matters. File extensions → $=; ID prefixes → ^=.

Example 3 — Select Links Ending in .pdf

A common real-world pattern: target download URLs by file extension.

jQuery
var hrefs = $("a[href$='.pdf']").map(function () {
  return $(this).attr("href");
}).get().join(", ");

console.log(hrefs);
// /files/guide.pdf  (.PDF is skipped — case-sensitive)
Try It Yourself

How It Works

  1. Target anchors. a[href$=…] only considers links.
  2. Exact suffix. The URL must end with .pdf.
  3. Case matters. .PDF is a different ending.
  4. Practical use. Style or count downloadable document links.

Example 4 — Match Elements by id Suffix

Select nodes whose id ends with a shared token.

jQuery
var ids = $("[id$='-panel']").map(function () {
  return this.id;
}).get().join(", ");

console.log(ids);
// main-panel, side-panel
Try It Yourself

How It Works

  1. Any element. Omitting a tag searches every node with an id.
  2. Shared ending. Both main-panel and side-panel end with -panel.
  3. Order matters. panel-main fails because it ends with main.
  4. Naming tip. Consistent ID suffixes make group selection easy.

Example 5 — Case Sensitivity

Official rule: the comparison is case sensitive — casing must align.

jQuery
console.log("letter :", $("input[name$='letter']").length);
console.log("Letter :", $("input[name$='Letter']").length);

// name="myLetter" matches only the second query
Try It Yourself

How It Works

  1. Same letters, different case. Selectors compare the suffix as written.
  2. Lowercase query. Matches values ending in lowercase letter.
  3. Capitalized query. Matches values ending in Letter.
  4. Habit. Normalize file extensions and suffixes in markup when possible.

Edge Cases & Pitfalls

Check these before relying on $= in real projects.

case

Case-sensitive by design

Official docs state the comparison is case sensitive. .pdf and .PDF need separate selectors (or normalized URLs).

trap

Contains ≠ ends with

letterbox contains letter but fails $=. Use *= if the fragment can sit anywhere.

query

Query strings break file suffixes

file.pdf?v=2 does not end with .pdf. Strip query params first, or match a broader pattern.

empty

Empty suffix is a trap

[attr$=""] can match every element that has that attribute. Avoid empty search strings.

Browser Support

The attribute ends-with selector [attr$="value"] is part of CSS3 and has worked in jQuery since 1.0. Modern browsers implement it in native querySelectorAll.

✓ CSS3 · jQuery 1.0+

jQuery [name$="value"]

Supported in all modern browsers. Native: document.querySelectorAll("input[name$='letter']"). Case-sensitive suffix matching.

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
$= combinator Universal

Bottom line: Safe everywhere jQuery runs. Ideal for suffixes and file extensions — keep casing consistent in markup and selectors.

Performance Notes

ApproachCostBest for
$("input[name$='letter']")Native-friendly CSSScoped form controls
$("a[href$='.pdf']")Native-friendly CSSFile-type link filters
$("[id$='-panel']")Wider scanAny element with that id suffix

Attribute selectors are standard CSS, so jQuery can often use the browser engine. Narrow with a tag or a container on large pages.

Key Takeaways

  • Role: match attributes whose value ends with an exact suffix.
  • Classic use: $("input[name$='letter']") from the official demo.
  • Case-sensitive: .pdf ≠ .PDF.
  • Not *=: ending with ≠ containing somewhere in the middle.

One line: use [attr$="value"] for exact, case-sensitive suffix matches — great for extensions and naming endings.

Frequently Asked Questions

It selects elements whose named attribute value ends exactly with the given string. For example, [name$="letter"] matches name="newsletter" and name="loveletter" because those values end with the suffix letter.
Yes. Per the official jQuery API, the comparison is case sensitive. name="myLetter" does not match [name$="letter"] because the casing differs at the end.
[attr$="pdf"] matches only when the value ends with pdf. [attr*="pdf"] matches pdf anywhere. [attr^="pdf"] matches values that start with pdf.
Yes. The attribute ends-with selector is standard CSS3 and has worked in jQuery since 1.0, with native querySelectorAll support in modern browsers.
Yes. a[href$=".pdf"] is a common pattern for URLs that end with the .pdf extension — remember case sensitivity (.PDF vs .pdf).
No. The value must end with the exact suffix letter. letterbox ends with box, not letter. Use [name*="letter"] if you need substring matching anywhere.

Next: Multiple Attribute Selector

Combine several attribute filters so every condition must match.

Multiple [attr] 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.

9 people found this page helpful