Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can more than one JavaScript handler register to an event?

Can more than one JavaScript handler register to an event such as window.onresize? I tried using +=, but that had no effect. Only = and that obviously replaces any previously assigned events.

like image 817
Matt Avatar asked Feb 26 '23 22:02

Matt


1 Answers

For IE you can use: window.attachEvent('onresize', handler);

where handler is your handler function.

In all other browsers you can use: window.addEventListener('resize', handler);

Both of these functions can be used multiple times to attach multiple event handlers.

like image 107
Dylanado Avatar answered Apr 30 '23 04:04

Dylanado