How to implement jQuery live bind event on mootools?

How to create elements that are loaded via ajax, accept events related to the same class on mootools 1.11?

As far as I know, in jQquery, if your ajax answer consists of something like <div class='button'>,
if there is a binding to the event using liveto $('.button'), these events will automatically bind.

Is this possible with MooTools 1.11?

+3
source share
4 answers

Perhaps something like this can do what you are looking for? Although I'm not sure that it will work from 1.11.

Element.implement({
    addLiveEvent: function(event, selector, fn){
        this.addEvent(event, function(e){
            var t = $(e.target);

            if (!t.match(selector)) return false;
                fn.apply(t, [e]);
        }.bindWithEvent(this, selector, fn));
    }
});

$(document.body).addLiveEvent('click', 'a', function(e){ alert('This is a live event'); });
+7
source

anomareh is on the right track.

.

, , ( , Mootools ).

+1

, jQuery .live() , . - stopPropagation() , .

, , , :

http://www.nczonline.net/blog/2010/03/09/custom-events-in-javascript/

But in this example, bubbling of events has not yet been implemented. Some kind of bubble that has a rollback to prevent should solve the problem.

+1
source

You can use this method:

$(document.body).addEvent('click:relay(.filterButton)', function(){
// do something
});
+1
source

Source: https://habr.com/ru/post/1729359/


All Articles