:root
S2C 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
ExampleTop
Selects the root element of the document.
The following example will alert the value of the 'root' element.
$(function(){
$('#btn1').on('click', function() {
alert('The root element has a value of: ' + $( ":root" )[0].nodeName );
});
});