Alex Alex - 21 days ago 6
Javascript Question

addEventListener Two Functions

I was wondering if addEventListener could have two functions inside it.
I have tried it but it seems not to work.
Please give me a simple example if it is possible.

Thanks,

Alex

Answer

Wrap your functions in a function.

function invokeMe() { console.log('I live here outside the scope'); }

function alsoInvokeMe() { console.log('I also live outside the scope'); }

element.addEventListener('event', function() {

     invokeMe();
     alsoInvokeMe();

});