title: How to add a onclick event to an element using javascript
body: <p>I have created an element using document.getElementsByClassname, and would like to add a onclick event to this element, so that when someone clicks on this element onclick function should be called.</p>
  
  <p>I tried with event listener, but this will execute even when I don't click on any function.
  Using jQuery we can do that by binding a click event, but I my requirement is in javascript/</p>
  
  <p>Thanks!</p>
  
  <pre><code>element.addEventListener("click", alert('clicked'), false);// Add onclick eventListener 
  
  var element= document.getElementsByClassName('classname');
  </code></pre>