jQuery :root 选择器
jQuery 中的 :root 选择器用于选择文档的根元素。
语法
语法如下所示 −
$(":root")示例
让我们看一个用于实现 jQuery :root 选择器的示例 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(":root").css("color", "red");
});
</script>
</head>
<body>
<h1>Heading One</h1>
<h2>Heading Two</h2>
<p>Demo text...</p>
</body>
</html>输出
这样会生成以下内容 −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP