Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body onclick="myFunction(event)" style="border:1px solid black;Padding:8px"> <h1>HTML DOM Events</h1> <h2>The currentTarget Property</h2> <p>Click on any elements in this document to find out which element triggered the onclick event.</p> <button>This is a button</button> <p>The <b>currentTarget</b> property refers to the element whose event listener triggered the event.</p> <p>This is opposed to the <b>target</b> property, which returns the element that triggered the event.</p> <p id="demo"></p> <script> function myFunction(event) { let text = event.currentTarget.tagName; document.getElementById("demo").innerHTML = text; } </script> </body> </html>