javascript button onclick

JavaScript
var button = document.querySelector('button');
button.onclick = function() {
  //do stuff
}document.getElementById('button').onclick = function() {
   alert("button was clicked");
};<button onclick="myFunction()">Click me</button>
 <button onClick="script">
var myElem = document.getElementByID('ElemID');
myElem.onclick = function() {
	//do stuff
}var element = document.getElementById("elem");
element.onclick = function(event) {
  console.log(event);
}
Source

Also in JavaScript: