:rootS2C Home « Selectors « :root

Document root element selector.

Shorthand version $(':root')

Description

The :root selector returns the document root element.

  • This will always select the <html></html> element which is the root of all HTML documents.

Syntax


Signature Description
jQuery(':root')Last of type selector match

Parameters

None.

Return

N/A.

:root Examplego to top of page Top

Selects the root element of the document.

The following example will alert the value of the 'root' element.


$(function(){
  $('#btn32').on('click', function() {
  	alert('The root element has a value of: ' + $( ":root" )[0].nodeName );
  });
}); 

Press the button below to action the above code:


go to home page Homepage go to top of page Top