I have this object I need to create with JS and later on I need to do an on hover do something statement…And because this div is created clientside later, my hover statement doesn’t apply…So my question is, can I somehow live create this just like I was to use jquery.live() but with plain JS?
var parentContainer = document.getElementById('box');
var someContainer = document.createElement("div");
someContainer.className = "fun";
parentContainer.appendChild(someContainer);
jQuery("#box").hover(function() {
jQuery("#box .fun").fadeIn('fast');
});
So this obviously does not work because of the live bind issue…
Thanks for the help.
What needs to be live is the
hoverfunction, not the object.Live means the event handler is placed at the root of the DOM tree, and if it matches your selector it will trigger.
Read more about how
.live()works in jQuery’s API documentation.