Como selecionar o elemento raiz do documento em jQuery?


Para selecionar o elemento raiz do documento em jQuery, podemos usar o método document ou $() com o seletor document. Ambos retornarão o elemento raiz do documento.

Exemplo usando document:

var rootElement = $(document);

Exemplo usando $() com o seletor document:

var rootElement = $('document');

Podemos então usar o objeto rootElement para acessar e manipular o elemento raiz do documento.



About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.