How does jQuery know when any DOM event happens?
$('body').on('click', function(e) {
alert('working');
});
document.body.onclick; // null
I rely on this library way too much. Can someone tell me how it knows when the body is clicked?
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.
.onwrapsjQuery.event.add(if you look at the jQuery source that is on line 2688).This attempts to use a cached version of the event type, but if there is none it eventually boils down to calling the browser-specific functions for attaching events (on around line 2767).
It doesn’t seem to have a fallback for the case of neither of these, so the
on*attributes are never written to. Hence,elem.onclickwill be empty if you usejQuery.onFor reference: http://code.jquery.com/jquery.js