If I append new div on the run, the newly created div doesn’t get connected with event handler in document ready.
for example, http://jsfiddle.net/nFG24/
how to assign new div to current event handler in document ready?
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.
The shortcut event handlers (such as
click(),mouseover()etc) will only apply to elements which are available to the DOM on page load. When appending elements dynamically you have to attach the event to a static parent element, and supply a filter which you wish to delegate events to, like this:Note that I’ve used
bodyhere as the primary selector. Ideally you should use the closest containing element to the.hovermeelements which is not dynamically appended to the DOM.Working fiddle
Also, you can slightly tidy your code by using
hover():Example fiddle