jquery - Trigger multi-events -


can trigger multi events in trigger() or chain them in jquery!? e.g:

$(element).trigger('event1 event2 event3'); 

or

$(element).trigger('event1').trigger('event2'); 

or

$(element).trigger('event1'); $(element).trigger('event2'); 

as other answers note, best built-in method is:

$(element).trigger('event1').trigger('event2'); 

however, find if you're doing on place, simple plugin cleans quite nicely, allowing space-separated syntax (like other jquery methods). here's quick example of such plugin:

$.fn.triggerall = function(events) {     if(!events) return this; //don't blow if .triggerall() without params     var self = this;         //keep reference     $.each(events.split(" "), function(i, e) { self.trigger(e); });     return this; }; 

then can call space-separated event names, this:

$(element).triggerall('event1 event2 event3'); 

you can test out here


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -