Which is the best way (performance-wise) to get the root document node (the <html> element) in jQuery? I can think of several methods that may or may not work:
$("html")
$(document.documentElement)
$(document) (?)
$.root (?)
$.document (?)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$(document.documentElement)is the fastest, by quite some margin (see tests here).You can get more insight as to why this is the case by looking at the jQuery source code (look at the
initfunction, in particular, the part that handles a DOM element, and the part that handles a string).