<html>
<body>
<h1>The Element Object</h1>
<h2>The addEventListener() Method</h2>
<p>Execute a function when a user clicks on a button:</p>
<button id="myBtn">Try it</button>
<p id="demo">
<script>
const element = document.getElementById("myBtn");
element.addEventListener("click", myFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_addeventlistener2 by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:43 GMT -->
</html>