jQuery :header Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:header (since jQuery 1.2) selects all heading elements — h1 through h6 — in one expression. It matches real heading tags only, not “title-looking” div or p elements.

Syntax

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

jQuery
$(":header")                         // all h1–h6 on the page
$("article :header")                 // headings inside article only
$("#main *").filter(":header")       // faster scoped pattern

// Same matches as:
$("h1, h2, h3, h4, h5, h6")
CallWhat it does
:headerMatch h1–h6
Context / prefixLimit search (e.g. article :header)
.filter(":header")Recommended performance pattern
Return valuejQuery set of heading elements

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

Parameters

ParameterDescription
":header"Used in .filter(":header"). Recommended performance pattern

Return Value

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

jQuery Examples

Example 1 — Select All Headings

Official idea: match every h1–h6 and mark them.

jQuery
$(":header").each(function () {
  $(this).append(" [header]");
});
Try It Yourself

How It Works

  1. Select. $(":header") finds all heading tags.
  2. Skip. Paragraphs and other tags are not included.
  3. Each. Loop marks every matched heading.

Example 2 — Performance: .filter(":header")

Official tip: CSS-select a region first, then filter headings.

jQuery
$("#content *").filter(":header").each(function () {
  $(this).append(" [in content]");
});
Try It Yourself

How It Works

  1. CSS first. $("#content *") uses a fast native path.
  2. Filter. .filter(":header") keeps only heading tags.
  3. Scope. Sidebar headings are outside #content.

Example 3 — Scoped: article :header

Limit matches to headings inside article only.

jQuery
$("article :header").each(function () {
  $(this).append(" [article]");
});
Try It Yourself

How It Works

  1. Descendant. Space means “inside article”.
  2. Match. Only headings nested under article.
  3. Aside. Sibling regions are ignored.

Frequently Asked Questions

:header selects every heading element — h1, h2, h3, h4, h5, and h6. One pseudo-class replaces writing h1, h2, h3, h4, h5, h6 when you need all heading levels. Available since jQuery 1.2.
No. :header only matches real h1–h6 tags. A div with class "title" or a bold paragraph is not a header unless it uses a heading tag.
No. It is a jQuery extension and cannot use the native querySelectorAll() boost. The CSS-equivalent selector is h1, h2, h3, h4, h5, h6.
Official docs recommend a pure CSS select first, then .filter(":header"). Example: $("#main *").filter(":header") instead of bare $(":header") on large pages when you only care about one region.
Yes. Prefix with a container — $("article :header") matches only headings inside article elements.
:header matches element type (heading tags). :contains() matches text substrings. :has() matches parents that contain a descendant. They solve different problems.

Next: :hidden Selector

Select elements that jQuery considers hidden — display, visibility, and more.

:hidden 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.

10 people found this page helpful