jQuery Attribute Starts With [name^="value"]

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

What Is [name^="value"]?

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

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

$("input[name^='news']")
  ✓ name="newsletter"
  ✓ name="newsboy"
  ✗ name="milkman"      (starts with "milk")
  ✗ name="Newsletter"   (case differs)

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

How to Use [name^="value"]

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

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

Pseudocode

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

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

return jQuery(matches)

Cheat Sheet

Keep these facts handy while matching attribute prefixes.

TopicDetail
Syntax$("[attr^='value']")
MatchesValue beginning exactly with the prefix
Classic use$("input[name^='news']")
HTTPS links$("a[href^='https://']")
ID prefixes$("[id^='ctl00_']") (framework IDs)
CaseSensitive (news ≠ News)
vs $= / *=End only / anywhere
SincejQuery 1.0 (CSS3)

Live Preview

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

Sample markup mirrors the official jQuery name^='news' demo, plus HTTPS link examples.

Result
$("input[name^='news']")
matched: 2
names: newsletter, newsboy

/* starts exactly with news */

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^="news"]

Find inputs whose name starts with news, then set a new value.

jQuery
$("input[name^='news']").val("news here!");

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

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

How It Works

  1. Limit to inputs. The input tag keeps the search on form controls.
  2. Apply ^=. Only names that begin with news match.
  3. Skip mid-word hits. A name like my_news would fail — prefix must be first.
  4. Set values. .val() updates every prefix match in one call.

Example 2 — ^= vs $=

Contrast starting with news against ending with news.

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

// ^= matches newsletter, newsboy
// $= matches none in the official sample (no name ends with "news")
Try It Yourself

How It Works

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

Example 3 — Select Links Starting with https://

A common real-world pattern: target secure external URLs by scheme.

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

console.log(hrefs);
// https://example.com  (http:// and /about are skipped)
Try It Yourself

How It Works

  1. Target anchors. a[href^=…] only considers links.
  2. Exact prefix. The URL must begin with https://.
  3. Scheme matters. http:// is a different start.
  4. Practical use. Style or count secure outbound links.

Example 4 — Match Elements by id Prefix

Useful for systematic IDs from server-side frameworks (official API tip).

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

console.log(ids);
// row-1, row-2
// (panel-row is skipped — prefix, not suffix)
Try It Yourself

How It Works

  1. Any element. Omitting a tag searches every node with an id.
  2. Shared start. Both row-1 and row-2 begin with row-.
  3. Order matters. panel-row fails because it starts with panel.
  4. Prefer classes. Official docs note classes are usually faster for grouping.

Example 5 — Case Sensitivity

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

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

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

How It Works

  1. Same letters, different case. Selectors compare the prefix as written.
  2. Lowercase query. Matches values starting with lowercase news.
  3. Capitalized query. Matches values starting with News.
  4. Habit. Keep prefixes consistent 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. news and News need separate selectors (or normalized values).

trap

Contains ≠ starts with

my_news contains news but fails ^=. Use *= if the fragment can sit anywhere.

perf

Classes beat attribute prefixes

Official API tip: systematic IDs work with ^=, but grouping with a class is usually faster.

empty

Empty prefix is a trap

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

Browser Support

The attribute starts-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^='news']"). Case-sensitive prefix 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 prefixes, schemes, and systematic IDs — keep casing consistent in markup and selectors.

Performance Notes

ApproachCostBest for
$("input[name^='news']")Native-friendly CSSScoped form controls
$("a[href^='https://']")Native-friendly CSSScheme / URL filters
$("[id^='row-']")Wider scanAny element with that id prefix
$(".group")Usually fasterPrefer classes when you control markup

Attribute selectors are standard CSS, so jQuery can often use the browser engine. Narrow with a tag or a container on large pages — and prefer a class when you can add one.

Key Takeaways

  • Role: match attributes whose value starts with an exact prefix.
  • Classic use: $("input[name^='news']") from the official demo.
  • Case-sensitive: news ≠ News.
  • Not *=: starting with ≠ containing somewhere in the middle.

One line: use [attr^="value"] for exact, case-sensitive prefix matches — great for schemes, naming starts, and systematic IDs.

Frequently Asked Questions

It selects elements whose named attribute value begins exactly with the given string. For example, [name^="news"] matches name="newsletter" and name="newsboy" because those values start with the prefix news.
Yes. Per the official jQuery API, the comparison is case sensitive. name="Newsletter" does not match [name^="news"] because the casing differs at the start.
[attr^="https"] matches only when the value starts with https. [attr*="https"] matches https anywhere. [attr$=".pdf"] matches values that end with .pdf.
Yes. The attribute starts-with selector is standard CSS3 and has worked in jQuery since 1.0, with native querySelectorAll support in modern browsers.
Yes. a[href^="https://"] is a common pattern for URLs that begin with the https:// scheme.
No. The prefix must be the first characters of the value. my_news starts with my_, not news. Use [name*="news"] if the substring may appear in the middle.

Next: [name$="value"]

Match attribute values that end with an exact suffix.

$= 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.

9 people found this page helpful