jQuery Header element selector

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(){<!--   ww  w.  j  a  v a 2 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





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities