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

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

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

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

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

$=  ≠  ^=   // ^= is start only
$=  ≠  *=   // *= is anywhere
CallWhat it does
See the examples below.

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

Parameters

ParameterDescription
Step 1Choose the attribute (name, href, id, …).
Step 2Write $("[attr$='suffix']") — or with a tag: $("input[name$='letter']").
Step 3Confirm the value truly ends with that string (not just contains it).

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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.

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 Attribute Selector 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.

9 people found this page helpful