jQuery :root 伪类选择器

时间:2022-12-18 16:41:29
<!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>