Header selector

The selector :header selects headers h1, h2, h3, h4, h5, h6. Since :header is not part of the CSS specification, it is better to use it in modern browsers to improve performance. First filter the elements using a pure css selector, then apply .filter(':header').

Syntax

This is how we select elements:

javascript$(':header');

Example

Let's change the background of all headings to gray:

html<h1>Header h1</h1>
<p>text</p>
<h2>Header h2</h2>
<p>text</p>
javascript$(':header').css({background: '#ccc'});

See also

  • method filter,
    which filters elements in a set by a given selector
  • method css,
    which allows you to get and change the CSS styles of an element