Javascript examples for DOM:Event
target Event Property - Using event.target with the element.tagName to find out which element triggered the event
<!DOCTYPE html> <html> <body onclick="myFunction(event)"> <p>Click me.</p> <h1>This is a heading</h1> <button>This is a button</button> <p id="demo"></p> <script> function myFunction(event) {//from w ww . j av a 2s . com var x = event.target; document.getElementById("demo").innerHTML = "Triggered by a " + x.tagName + " element"; } </script> </body> </html>