JS tip: How to call multiple functions from a Single eventListner

← PrevNext →

Let us assume, I have two functions that I need to call from a single eventListner, when I click an element. A simple solution is to wrap the two functions (you want to call) inside the eventListner function.

➡️ JavaScript Methods

<body>
  <p id='p1'>
    Click it
  </p>
</body>
<script>
  p1.addEventListener('click', (e) => {
    say_hello();
    show_date();
  });
  
  const say_hello = () => {
    alert('Hello');
  }
  const show_date = () => {
    const dt = new Date();
    alert('Today is: ' + dt.toDateString());
  }
</script>
Try it

➡️ More date and time example

← PreviousNext →