Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onclick Event</h2>
<p>Use the addEventListener() method to attach a "click" event to a p element:</p>
<p id="demo">Click me.</p>
<script>
document.getElementById("demo").addEventListener("click", myFunction);
function myFunction() {
  document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick_addeventlistener by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:58 GMT -->
</html>