Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add additional event handler in jQuery or plain javascript?

I have my own object with onShow() function, which is called (by me) when object is shown. I can override this function by assignment

o.onShow = function() { // something };

But it removes previous version of a function. So, if I wish to conserve existing handler, I should cache it and call in new handler:

o.oldOnShow = o.onShow;
o.onShow = function() { this.oldOnShow(); // something };

But this way I can cache only one previous handler. What if there are many of them?

Is there a convenient way to accomplish this task? How this task is named in literature? Is there a methods for this in jQuery?

like image 729
Dims Avatar asked Nov 22 '25 23:11

Dims


1 Answers

In jQuery you can add as many handlers as you like:

$(o).on('show', function() { ... });

Subsequent calls won't remove previously-bound handlers.

like image 175
Pointy Avatar answered Nov 25 '25 13:11

Pointy