Get the element that triggered a specific event:
The target property returns the element that triggered the event, and not necessarily the eventlistener's element.
<!DOCTYPE html> <html> <body onclick="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {/*from w w w .j a v a2 s . c o m*/ document.getElementById("demo").innerHTML = event.target.nodeName; } </script> </body> </html>
The target event property returns the element that triggered the event.