jqueryhoverintentjquery-on

jQuery.on() - how initialize as soon as elements have been loaded


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?


Solution

  • 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
        });
    });