jQuery :root Selector


The :root selector in jQuery is used to select the document's root element.

Syntax

The syntax is as follows −

$(":root")

Example

Let us now see an example to implement the jQuery :root selector −

<!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>

Output

This will produce the following output −

Updated on: 05-Nov-2019

120 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements