<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>:root</title>
<style>
.focused {
background: #abcdef;
}
</style>
</head>
<script src="jquery-3.1.1.js">
</script>
<body>
<!--:root选择文档的根元素
在HTML中,文档的根元素,和$(":root")选择的元素一样, 永远是<html>元素。
-->
</body>
<script type="text/javascript">
$(':root').css('background','lightgreen');
//相当于给html设置一个背景色
</script>
</html>jQuery :root 伪类选择器
最新推荐文章于 2025-07-14 22:10:44 发布
本文介绍如何使用CSS的$:root选择器来选择HTML文档的根元素,并通过jQuery来改变其背景颜色。$:root选择器总是选择文档的根元素,在HTML中即为<html>元素。

620

被折叠的 条评论
为什么被折叠?



