:header Selector

header selector

version added: 1.2jQuery(':header')

描述: 选择所有标题元素,像h1, h2, h3 等.

Example:

Adds a background and text color to all the headers on the page.

<!DOCTYPE html>
<html>
<head>
  <style>
  body { font-size: 10px; font-family: Arial; } 
  h1, h2 { margin: 3px 0; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <h1>Header 1</h1>

  <p>Contents 1</p>
  <h2>Header 2</h2>
  <p>Contents 2</p>
<script>$(":header").css({ background:'#CCC', color:'blue' });</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版脚本之家整理、修订 (2011年6月)