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

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

What You’ll Learn

The attribute ends-with selector — written [name$="value"] — matches elements whose attribute value ends with your search string. Matching is case-sensitive. It is ideal for file extensions, ID suffixes, and naming conventions — available since jQuery 1.0.

01

Syntax

[attr$="x"]

02

Suffix

Ends exactly

03

Case

Sensitive

04

Official

name$=letter

05

vs ^= *

End not start

06

Since 1.0

CSS3 + jQuery

Introduction

Many real-world naming patterns use suffixes: file extensions (.pdf, .min.js), field names (billing_email), and error-state IDs (username-error). The ends-with attribute selector lets you target those elements without listing every full name.

The dollar-equals syntax [attribute$="value"] checks whether the attribute string ends with your suffix — nothing may follow it. jQuery has supported this selector since version 1.0, and browsers implement it natively through CSS3 attribute selectors.

Understanding the Ends-With Selector

Think of the attribute value as text on a line. The selector asks: “Do the last characters exactly equal my suffix?” If yes, the element matches.

  • name="newsletter" + [name$="letter"] → matches (ends with letter).
  • name="letter" + [name$="letter"] → matches (entire value is the suffix).
  • name="letterbox" + [name$="letter"] → no match (ends with box).
  • href="/docs/guide.pdf" + [href$=".pdf"] → matches.
💡
Beginner Tip

If you need the substring anywhere in the value — not strictly at the end — use [attr*="value"] instead. Ends-with is stricter and usually clearer for extensions and suffix conventions.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( "[attribute$='value']" )
// shorthand:
$( "[attribute$='value']" )

// common patterns:
$( "input[name$='letter']" )
$( "a[href$='.pdf']" )

Parameters

  • attribute — the HTML attribute name (name, href, id, etc.).
  • value — suffix string the attribute value must end with (case-sensitive).

Return value

  • A jQuery object containing every element whose attribute ends with the suffix.
  • Empty collection when no values match.

Official jQuery API example

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

// Matches name="newsletter", name="loveletter", name="letter"
// Does NOT match name="letterbox" or name="letters"

⚡ Quick Reference

name value[name$="letter"]
newsletterMatches
loveletterMatches
letterMatches
letterboxNo match
lettersNo match (ends with s)
myLetterNo match (case differs)

📋 [attr$="x"] vs [attr^="x"] vs [attr*="x"]

Three substring operators — suffix, prefix, and anywhere — answer different questions.

Ends $
[href$=".pdf"]

Suffix at end

Starts ^
[href^="https"]

Prefix at start

Contains *
[href*="pdf"]

Anywhere in value

Exact =
[href=".pdf"]

Full value only

Examples Gallery

Example 1 follows the official jQuery API demo. Examples 2–5 cover suffix rules, operator comparison, PDF links, and scoped form fields. Use the Try-it links to run each snippet.

📚 Official jQuery Demo

Set text on inputs whose name ends with letter.

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

Official jQuery demo — fill inputs whose name attribute ends with the suffix letter.

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

// Matches: newsletter, loveletter, letter
// Skips: letterbox, letters, username
Try It Yourself

How It Works

jQuery compares the end of each name string to letter. Characters before the suffix do not matter — only the final characters must match exactly.

Example 2 — Test Suffix Matching with .is()

Programmatically verify which name values end with letter.

jQuery
var names = [ "newsletter", "letter", "letterbox", "letters", "loveletter" ];

names.forEach( function( n ) {
  var $el = $( "<input>" ).attr( "name", n ).appendTo( "body" );
  console.log( n, "→", $el.is( "[name$='letter']" ) ? "MATCH" : "no" );
  $el.remove();
});
Try It Yourself

How It Works

letterbox contains letter as a substring but does not end with it — a common beginner mistake that *= would match but $= correctly rejects.

📈 Practical Patterns

Operator comparison, file links, and scoped queries.

Example 3 — $= vs ^= vs *= on the Same URL

See how each operator behaves on an attribute value like a path or URL.

jQuery
var path = "/assets/report.pdf";
var $a = $( "<a>" ).attr( "href", path ).appendTo( "body" );

console.log( "href:", path );
console.log( "$=.pdf:", $a.is( "[href$='.pdf']" ) );
console.log( "^=/assets:", $a.is( "[href^='/assets']" ) );
console.log( "*=report:", $a.is( "[href*='report']" ) );

$a.remove();
Try It Yourself

How It Works

All three can match the same element for different reasons. Choose the operator that expresses your intent — suffix for extensions, prefix for paths, contains for loose substring search.

Example 4 — Highlight PDF Links with a[href$='.pdf']

Style download links whose URL ends with the .pdf extension.

jQuery
$( "a[href$='.pdf']" ).addClass( "pdf-link" );

// Matches /docs/guide.pdf and /files/annual-report.pdf
// Does not match /pdf-index or links without .pdf suffix
Try It Yourself

How It Works

The suffix must be the final characters of href. Query strings after .pdf (e.g. file.pdf?v=2) would not match — plan suffix patterns accordingly.

Example 5 — Scoped Fields #form input[name$='_confirm']

Target confirmation inputs inside one form by naming suffix convention.

jQuery
$( "#form input[name$='_confirm']" ).addClass( "confirm-field" );

// Matches email_confirm, password_confirm inside #form
// Ignores same names in other forms on the page
Try It Yourself

How It Works

Teams often suffix related fields with _confirm or _error. The ends-with selector groups them without maintaining a long list of full names.

🚀 Common Use Cases

  • File extensionsa[href$='.pdf'], script[src$='.min.js'].
  • Field suffixesinput[name$='_confirm'] for confirmation inputs.
  • Error states[id$='-error'] to style validation messages.
  • Image formatsimg[src$='.webp'] for modern image assets.
  • Locale fileslink[href$='.css'] vs script endings in bundler output.
  • Legacy IDs[id$='_old'] during migration cleanup.

🧠 How jQuery Evaluates [attr$="value"]

1

Read attribute

Get the full string value from each candidate element.

DOM
2

Compare suffix

Check whether the value ends with the search string — case-sensitive.

Suffix
3

No trailing chars

Nothing may follow the suffix — .pdf?v=1 fails $='.pdf'.

Exact end
4

Return collection

Matching elements become a jQuery object for chaining.

📝 Notes

  • Available since jQuery 1.0 — standard CSS3 attribute selector.
  • Comparison is case-sensitive (per official jQuery docs).
  • Suffix must be the final characters — query strings or hashes after the suffix break the match.
  • Not the same as *= — substring anywhere vs strict suffix.
  • Pair with element type and ID for performance: #downloads a[href$='.pdf'].
  • For values ending in mixed case extensions, normalize in markup or match both patterns in JS.

Browser Support

The attribute ends-with selector is part of CSS3 and works in jQuery 1.0+. Evergreen browsers support it in native querySelectorAll. IE7+ supports attribute selectors with jQuery fallbacks where needed.

CSS3 · jQuery 1.0+

jQuery [attribute$="value"]

Supported in all modern browsers. Native: document.querySelectorAll("a[href$='.pdf']"). Case-sensitive matching 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
[attr$="value"] Universal

Bottom line: Ideal for file extensions and suffix naming. Use ^= for prefixes and *= when the substring may appear in the middle.

Conclusion

The attribute ends-with selector [name$="value"] matches when an attribute value ends with your suffix — case-sensitive and exact at the tail. jQuery’s official demo, $("input[name$='letter']").val("a letter"), demonstrates the pattern on form field names.

Use $= for extensions and suffix conventions; use ^= for prefixes and *= when position does not matter. Scope selectors to keep queries fast and readable on large pages.

💡 Best Practices

✅ Do

  • Use a[href$='.pdf'] for file-type link styling
  • Include the dot in extensions: $='.pdf' not $='pdf' alone
  • Scope: $("#form input[name$='_confirm']")
  • Remember case sensitivity in HTML attributes
  • Choose $= when suffix position matters

❌ Don’t

  • Expect letterbox to match [name$="letter"]
  • Use $= when *= is what you really need
  • Forget query strings after extensions break strict suffix match
  • Assume .PDF matches $='.pdf'
  • Match very short suffixes like $='s' without testing over-match risk

Key Takeaways

Knowledge Unlocked

Five things to remember about [attr$="value"]

Suffix match at the end of the value.

5
Core concepts
Aa 02

Case

Sensitive

Rule
.pdf 03

Extensions

Common use

Pattern
≠ * 04

Not *=

Strict tail

Compare
letter 05

Official

name$=letter

Demo

❓ 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. jQuery and CSS attribute selectors use case-sensitive comparison for attribute values in HTML documents. name="myLetter" does not match [name$="letter"] because the casing differs at the end.
[attr$="pdf"] matches only when the value ends with pdf — report.pdf yes, pdf-guide no. [attr*="pdf"] matches pdf anywhere in the value. [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 to target download links whose URL path ends 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 in the value.
Did you know?

CSS attribute selectors form a family: = exact, ~= word, |= prefix, ^= starts-with, $= ends-with, and *= contains. Pick the narrowest operator that still matches your intent — ends-with is perfect for file extensions.

Continue to Multiple Attribute Selector

Chain attribute filters with AND logic — combine presence, equals, and suffix matching in one selector.

Multiple attribute selector 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