I'm trying to add the hoverIntent plugin to elements on my page, however some elements will be added to the DOM later on, which means I have to bind the plugin to future elements as well. How do you do that? I have seen the same questions on SO a few times, but nobody has a clear solution?
Use the "selector" parameter for event delegation.
$('#PARENT').hoverIntent({
over: function() {
console.log($(this));
},
out: function(){
console.log($(this));
},
selector: '.CHILD'
});
Source: hoverIntent Documentation
There's no support in jQuery to do this; it's something the plugin itself must support. The most common approach is to simply re-initialize the plugin after adding new content; which normally isn't a problem.
Another option is to use the liveQuery
plugin, and do something like this;
$('yourSelector').livequery(function () {
$(this).hoverIntent({
// blah
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With