I have the following:
$("#menu, #home").on('click', 'a', function() {
// javascript code
});
But it’s not inside a document ready? Will it still work okay even if the #menu or #home are not yet part of the DOM?
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.
Yes this will work (if you’ll adjust a selector) without need to wait for a DOM ready as long as you use jQuery 1.7+ since this form of event binding is a something that was achieved using
liveordelegatein previous jQuery versions:See documentation for
live