Example:
$(document).click(function() { blah });
// and
$('html').click(function() { blah });
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.
I’ll answer the question in several parts.
In JavaScript (not just jQuery, but all JavaScript) the document keyword is a handle on the object that contains the HTMLDocument. You might use this handle in the following scenarios…
When you pass the document to jQuery, it parses the document into a jQuery object.
When you pass the “html” selector to jQuery, it uses this string to find any elements in the document object model that match the selector (in all cases, there will be one html element).
In reality, you won’t notice a difference in behaviour between these:
But the technical difference is that document is an object and ‘html’ is a string that is used to search for an element. Both the object and any matching elements are converted into jQuery objects.
As they all add a click event handler to the “visible” part of the page, which is the only part of the page a user can realistically click on.