jQuery :root 選擇器


jQuery 中的 :root 選擇器用於選擇文件的根元素。

語法

語法如下所示 −

$(":root")

示例

讓我們看一個用於實現 jQuery :root 選擇器的示例 −

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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>

輸出

這樣會生成以下內容 −

更新日期:2019 年 11 月 5 日

154 次瀏覽

開啟您的 職業生涯

完成課程後獲得認證

立即開始
廣告
© . All rights reserved.