The ':root Selector' is used to select the root element.
Just remember, the root element is always the <html> element.
Let us simplify with the below example.
<html>
<head>
<title> My First Programme </title>
</head>
<body>
<h1> JQuery </h1>
<div class = "newClass">
<p class = "para1"> First Paragraph </p>
<p class = "para2"> Second Paragraph </p>
<p class = "para3"> Third Paragraph </p>
</div>
<button> Click me </button>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$('button').click( function() {
$(':root').text("All the elements got replaced")
});
</script>
</body>
</html>
So, if you see the above output, on button click, all the contents of the HTML page got replaced with 'All the elements got replaced'.
And this happened with the ':root' element selector.
$('button').click( function() {
$(':root').text("All the elements got replaced")
});The moment the button is clicked, JQuery statement gets triggered.
$(':root').text("All the elements got replaced")And replaces all the contents of the HTML page with 'All the elements got replaced'.