JQuery.on () - how to initialize as soon as elements are loaded

I am trying to add the hoverIntent plugin to elements on my page, however some elements will be added later in the DOM, which means I have to bind the plugin to future elements, How do you do it? I have repeatedly seen the same questions on SO, but who has no clear solution?

+5
source share
4 answers

JQuery has no support for this; this is what the plugin itself should support. The most common approach is to simply reinitialize the plugin after adding new content; which is usually not a problem.

- liveQuery - :

$('yourSelector').livequery(function () {
    $(this).hoverIntent({
        // blah
    });
});
+2

selector " .

$('#PARENT').hoverIntent({
    over: function() {
        console.log($(this));
    },
    out: function(){
        console.log($(this));
    },
    selector: '.CHILD'
});

: hoverIntent

+9

- . hoverIntent.

, nil.

DOMSubtreeModifed .

0

jquery;

ABC = {
   init: function() {//all function names goes here
       ABC.myFunction1();
       ABC.myFunction2();
       ABC.myFunction3();
   },
   myFunction1: function() {
     //code
   },
   myFunction2: function() {
     //code
   },
   myFunction3: function() {
     //code
   }//dont put comma last one
}

$(function() {
    ABC.init();//calls all functions after everything is initialized and ready.
});
0

All Articles