Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get the Element that Triggered the Event in jQuery</title> <style> div, p, span{ padding: 30px; display: block; border: 3px solid #999; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $(document).click(function(event){ alert("You've clicked: " + event.target.nodeName + ", id: " + event.target.id); }); }); </script> </head> <body> <div id="myDiv"> <p id="myP"> <span id="mySpan">Just click anywhere.</span> </p> </div> </body> </html>