概述 header selector
返回值:Array<Element(s)>
描述:选择所有标题元素,像h1, h2, h3 等.
:header() 是一个 jQuery 延伸出来的一个选择器 并且不是的CSS规范的一部分, 使用:header()查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了在现代浏览器上获得更佳的性能,请使用.filter(":header") 代替。
示例
给页面内所有标题加上背景色
<h1>Header 1</h1>
<p>Contents 1</p>
<h2>Header 2</h2>
<p>Contents 2</p>
$(":header").css("background", "#EEE");
[ <h1 style="background:#EEE;">Header 1</h1>, <h2 style="background:#EEE;">Header 2</h2> ]
在页面上的所有的标题元素上添加背景和文本颜色。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>header demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.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>
运行一下