
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- 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 :root Selector
The :root selector in jQuery is used to select the root element of the document, i.e. the "<html> element.
Syntax
Following is the syntax of :root selector in jQuery −
$(":root")
Parameters
Following are the parameters of this method −
- ":root" − This selector selects the root element of the document.
Example 1
In the following example, we are demonstrating how to change the background color of the root element of the document using the jQuery :root selector −
<html> <head> <script src="https://code.jquery.com/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>
After executing the above program, the root element of the document (<html>) will be highlighted with lightblue background color.
Example 2
In this example, we are demonstrating how to add a border to all elements within the root element using the jQuery :root selector −
<html> <head> <script src="https://code.jquery.com/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>
When we execute the above program, the all elements within the root element will be highlighted with solid red borders.