JavaScript Programming JavaScript > Code Examples Which element was clicked Which element was clicked <html> <head> <title>Happy Codings :-) Code Samples for JavaScript</title> <script type="text/javascript"> function whichElement(event){ var tname tname=event.srcElement.tagName alert("You clicked on a " + tname + " element.") } </script> </head> <body onmousedown="whichElement(event)"> <p>Click in the document. </p> <h3>This is a header</h3> <p>This is a paragraph</p> <img border="0" src="http://www.happycodings.com/images/HappyCodings.png" width="50" height="50" alt="Ball"> </body> </html>