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

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

What You’ll Learn

The attribute starts-with selector — written [name^="value"] — matches elements whose attribute value begins with your search string. Matching is case-sensitive. It is ideal for URL schemes, ID prefixes, and grouped field names — available since jQuery 1.0.

01

Syntax

[attr^="x"]

02

Prefix

Starts exactly

03

Case

Sensitive

04

Official

name^=news

05

vs $= *

Start not end

06

Since 1.0

CSS3 + jQuery

Introduction

Many real-world naming patterns use prefixes: URL schemes (https://), server-generated IDs (ETI_1234), and grouped field names (billing_email, billing_city). The starts-with attribute selector lets you target those elements without listing every full name.

The caret-equals syntax [attribute^="value"] checks whether the attribute string begins with your prefix — nothing may precede it. jQuery has supported this selector since version 1.0, and browsers implement it natively through CSS3 attribute selectors.

Understanding the Starts-With Selector

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

  • name="newsletter" + [name^="news"] → matches (starts with news).
  • name="newsboy" + [name^="news"] → matches.
  • name="milkman" + [name^="news"] → no match (starts with milk).
  • href="https://example.com" + [href^="https://"] → matches.
💡
Beginner Tip

If you need the substring anywhere in the value — not strictly at the start — use [attr*="value"] instead. Starts-with is stricter and usually clearer for schemes and prefix conventions.

📝 Syntax

Official jQuery API form (since 1.0):

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

// common patterns:
$( "input[name^='news']" )
$( "a[href^='https://']" )

Parameters

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

Return value

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

Official jQuery API example

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

// Matches name="newsletter", name="newsboy"
// Does NOT match name="milkman"

⚡ Quick Reference

name value[name^="news"]
newsletterMatches
newsboyMatches
newsMatches (entire value is prefix)
milkmanNo match
my_newsNo match (prefix is my_)
NewsletterNo match (case differs)

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

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

Starts ^
[href^="https"]

Prefix at start

Ends $
[href$=".pdf"]

Suffix at end

Contains *
[href*="pdf"]

Anywhere in value

Exact =
[href="https"]

Full value only

Examples Gallery

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

📚 Official jQuery Demo

Set value on inputs whose name starts with news.

Example 1 — Official Demo: input[name^='news']

Official jQuery demo — fill inputs whose name attribute begins with the prefix news.

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

// Matches: newsletter, newsboy
// Skips: milkman
Try It Yourself

How It Works

jQuery compares the start of each name string to news. Characters after the prefix do not matter — only the opening characters must match exactly.

Example 2 — Test Prefix Matching with .is()

Programmatically verify which name values start with news.

jQuery
var names = [ "newsletter", "newsboy", "milkman", "news", "my_news" ];

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

How It Works

my_news contains news as a substring but does not start with it — a common beginner mistake that *= would match but ^= correctly rejects.

📈 Practical Patterns

Operator comparison, secure 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( "^=/assets:", $a.is( "[href^='/assets']" ) );
console.log( "$=.pdf:", $a.is( "[href$='.pdf']" ) );
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 — prefix for paths and schemes, suffix for extensions, contains for loose substring search.

Example 4 — Mark External Links with a[href^='https://']

Style links whose URL begins with the secure https:// scheme.

jQuery
$( "a[href^='https://']" ).addClass( "secure-link" );

// Matches https://example.com and https://docs.site/page
// Does not match http:// or relative /about links
Try It Yourself

How It Works

The prefix must be the first characters of href. Include the full scheme https:// so you do not accidentally match unrelated values that merely contain those letters elsewhere.

Example 5 — Scoped Fields #checkout input[name^='billing_']

Target billing fields inside one form by naming prefix convention.

jQuery
$( "#checkout input[name^='billing_']" ).addClass( "billing-field" );

// Matches billing_email, billing_city inside #checkout
// Ignores shipping_email and billing fields in other forms
Try It Yourself

How It Works

Teams often prefix related fields with billing_ or shipping_. The starts-with selector groups them without maintaining a long list of full names — jQuery docs note that shared CSS classes can be faster when you control the markup.

🚀 Common Use Cases

  • URL schemesa[href^='https://'], a[href^='mailto:'].
  • Field prefixesinput[name^='billing_'] for checkout forms.
  • Server IDs[id^='ETI_'] for framework-generated element IDs.
  • Path rootsa[href^='/docs/'] for documentation sections.
  • Data attributes[data-tab^='settings-'] for grouped tabs.
  • Image CDN pathsimg[src^='https://cdn.'] for asset origins.

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

1

Read attribute

Get the full string value from each candidate element.

DOM
2

Compare prefix

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

Prefix
3

No leading chars

Nothing may precede the prefix — relative paths need ^="/docs" not ^="docs" alone on full URLs.

Exact start
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).
  • Prefix must be the first characters — nothing may precede it.
  • Not the same as *= — substring anywhere vs strict prefix.
  • Official docs: useful for server-generated IDs, but CSS classes are often faster when you control markup.
  • Pair with element type and ID for performance: #checkout input[name^='billing_'].

Browser Support

The attribute starts-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^='https://']"). 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 URL schemes and field prefixes. Use $= for suffixes and *= when the substring may appear in the middle.

Conclusion

The attribute starts-with selector [name^="value"] matches when an attribute value begins with your prefix — case-sensitive and exact at the head. jQuery’s official demo, $("input[name^='news']").val("news here!"), demonstrates the pattern on form field names.

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

💡 Best Practices

✅ Do

  • Use a[href^='https://'] for secure external links
  • Include the full scheme or path prefix you need
  • Scope: $("#checkout input[name^='billing_']")
  • Remember case sensitivity in HTML attributes
  • Prefer shared CSS classes when you control the markup

❌ Don’t

  • Expect my_news to match [name^="news"]
  • Use ^= when *= is what you really need
  • Omit leading slashes on path prefixes (^="docs" vs full path)
  • Assume Newsletter matches ^="news"
  • Match very short prefixes like ^="n" without testing over-match risk

Key Takeaways

Knowledge Unlocked

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

Prefix match at the start of the value.

5
Core concepts
Aa 02

Case

Sensitive

Rule
https 03

Schemes

Common use

Pattern
≠ * 04

Not *=

Strict head

Compare
news 05

Official

name^=news

Demo

❓ 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. jQuery and CSS attribute selectors use case-sensitive comparison for attribute values in HTML documents. name="Newsletter" does not match [name^="news"] because the casing differs at the start.
[attr^="https"] matches only when the value starts with https — https://example.com yes, http://example.com no. [attr*="https"] matches https anywhere in the value. [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 to target secure external links whose URL begins 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.
Did you know?

CSS attribute selectors form a family: = exact, ~= word, |= prefix-with-hyphen, ^= starts-with, $= ends-with, and *= contains. The caret operator ^= is the mirror of dollar $= — one checks the head, the other checks the tail.

Continue to :button Selector

After prefix matching, learn how to select button elements and input[type=button] with :button.

:button 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