Search code examples
javascriptfunctionaddeventlistener

addEventListener Two Functions


How can I make it so that addEventListener() has two functions inside it?


Solution

  • Wrap your functions in a function.

    const invokeMe = () => console.log('I live here outside the scope');
    const alsoInvokeMe = () => console.log('I also live outside the scope'); 
    
    element.addEventListener('event',() => {    
         invokeMe();
         alsoInvokeMe();    
    });