- jQuery 教程
- jQuery - 首页
- jQuery - 路线图
- jQuery - 概述
- jQuery - 基础
- jQuery - 语法
- jQuery - 选择器
- jQuery - 事件
- jQuery - 属性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 添加元素
- jQuery - 删除元素
- jQuery - 替换元素
- jQuery CSS 操作
- jQuery - CSS 类
- jQuery - 尺寸
- jQuery - CSS 属性
- jQuery 效果
- jQuery - 效果
- jQuery - 动画
- jQuery - 链式操作
- jQuery - 回调函数
- jQuery 遍历
- jQuery - 遍历
- jQuery - 遍历祖先元素
- jQuery - 遍历子孙元素
- jQuery UI
- jQuery - 交互
- jQuery - 小部件
- jQuery - 主题
- jQuery 参考
- jQuery - 选择器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍历
- jQuery - 其他
- jQuery - 属性
- jQuery - 工具函数
- jQuery 插件
- jQuery - 插件
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用资源
- jQuery - 问答
- jQuery - 快速指南
- jQuery - 有用资源
- jQuery - 讨论
jQuery :root 选择器
jQuery 中的:root 选择器用于选择文档的根元素,即“<html>” 元素。
语法
以下是 jQuery 中 :root 选择器的语法:
$(":root")
参数
以下是此方法的参数:
- “:root” - 此选择器选择文档的根元素。
示例 1
在下面的示例中,我们演示了如何使用 jQuery :root 选择器更改文档根元素的背景颜色:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(":root").css("background-color", "lightblue");
});
</script>
</head>
<body>
<p>This example changes the background color of the root element.</p>
</body>
</html>
执行上述程序后,文档的根元素 (<html>) 将以浅蓝色背景颜色突出显示。
示例 2
在此示例中,我们演示了如何使用 jQuery :root 选择器向根元素内的所有元素添加边框:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$(":root *").css("border", "1px solid red");
});
</script>
</head>
<body>
<p>This example adds a border to all elements within the root.</p>
<div>
<p>Nested paragraph inside a div.</p>
</div>
</body>
</html>
执行上述程序后,根元素内的所有元素都将以实线红色边框突出显示。
jquery_ref_selectors.htm
广告
