vendredi 26 décembre 2014

jquery: stop infinite recursion?


How do I stop the infinite recursion here so that a mousedown event can be triggered just once?



$(document).on('mouseover',function (e) {
$(e.target).mousedown(function(e){
e.stopPropagation();
console.log('clicked');
$(e.target).trigger('mousedown');
return;
})
});

$(document).on('mousedown', 'a', function(e){
console.log('got it');
});


This seems to trigger a never ending loop. Basically I need to bind a mousedown handler on the currently element under the mouse, which will fire a mousedown event that another handler will be able to handle.


The reason I am doing this is because the mouseover works on dynamically generated element so when this happens I need to bind a handler again as the on handler is not able to catch the newly generated element.





Aucun commentaire:

Enregistrer un commentaire