:header Selector


header selector

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

  • 添加的版本: 1.2jQuery( ":header" )

Additional Notes:

  • 因为 :header() 是一个 jQuery 延伸出来的一个选择器 并且不是的CSS规范的一部分, 使用:header()查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了在现代浏览器上获得更佳的性能,请使用.filter(":header") 代替。

例子:

在页面上的所有的标题元素上添加背景和文本颜色。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!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.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: