| Viewed 150 times

How to add event listener in javascript

I`m trying to add onclick event in javascript

1 Answer
Mohammad Qandeel

In Javascript, there are a lot of events such as :

  • click
  • dblclick
  • mouseenter
  • mouseleave
  • mousemove


and  there are three ways to assign events to HTML elements:

  • Inline event handlers
  • Event handler properties
  • Event listeners


I will show you how to add onclick event in javascript using Inline event handlers 


<button onclick="alert(Date())">What the time is?</button>

Related Questions