jQuery中的:root選擇器用於選擇文檔的根元素。
用法:
$(":root")
參數:該選擇器包含單個參數root,它是文檔的根元素。
Example:本示例使用:根選擇器選擇文檔並將背景色設置為綠色。
<!DOCTYPE html>
<html>
<head>
<title>
jQuery:root Selector
</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body style = "text-align:center;">
<h1>GeeksForGeeks</h1>
<h2>jQuery:root Selector</h2>
<!-- Script uses:root selector -->
<script>
$(document).ready(function() {
$(":root").css("background-color", "green");
});
</script>
</body>
</html>
輸出:
相關用法
- jQuery :gt()用法及代碼示例
- jQuery :even用法及代碼示例
- jQuery :contains()用法及代碼示例
- jQuery :lt()用法及代碼示例
- jQuery :last用法及代碼示例
- jQuery :odd用法及代碼示例
- jQuery :not()用法及代碼示例
- jQuery :first用法及代碼示例
- jQuery :file用法及代碼示例
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 jQuery | :root Selector。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。