Header element (:header)

Description and Syntax

$(':header')

selects all elements that are headers, such as <h1> or <h2>.

Examples

  • $(':header') selects all header elements
  • $('.myclass:header') selects all header elements with the class myclass

<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
  $(document).ready(function(){<!--from   w  w  w .  j  av  a2 s .c  o m-->
     $(":header").css({ background:'#CCC', color:'blue' });
  });
    </script>

  </head>
  <body>
   <h1>Header 1</h1>
   <p>Contents 1</p>
   <h2>Header 2</h2>
   <p>Contents 2</p>
  </body>
</html>

Click to view the demo

The code above generates the following result.

Header element (:header)