Answers for "how to add click handler to an HTML element"

9

javascript click event

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Posted by: Guest on April-10-2020
3

javascript event listener

element.addEventListener("click", function(){ 
   element.innerText = "something"; 
});
Posted by: Guest on February-19-2020

Code answers related to "how to add click handler to an HTML element"

Browse Popular Code Answers by Language