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
Fundamentals
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.
Concept
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).
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.
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"
Cheat Sheet
⚡ Quick Reference
name value
[name$="letter"]
newsletter
Matches
loveletter
Matches
letter
Matches
letterbox
No match
letters
No match (ends with s)
myLetter
No match (case differs)
Compare
📋 [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
Hands-On
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
href: /assets/report.pdf
$=.pdf: true
^=/assets: true
*=report: true
Each operator checks a different part of the same string
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
PDF download links → class "pdf-link"
HTML page links → unchanged
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
Field suffixes — input[name$='_confirm'] for confirmation inputs.
Error states — [id$='-error'] to style validation messages.
Image formats — img[src$='.webp'] for modern image assets.
Locale files — link[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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about [attr$="value"]
Suffix match at the end of the value.
5
Core concepts
$01
$= syntax
Ends with
API
Aa02
Case
Sensitive
Rule
.pdf03
Extensions
Common use
Pattern
≠ *04
Not *=
Strict tail
Compare
letter05
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.