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

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

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

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

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

^=  ≠  $=   // $= is end 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^='prefix']") — or with a tag: $("input[name^='news']").
Step 3Confirm the value truly starts 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^="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.

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.

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.

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: Attribute Ends With Selector

Match attribute values that end with an exact suffix.

Attribute Ends With 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