Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body onmousedown="whichElement(event)">
<h1>HTML DOM Events</h1>
<h2>The onmousedown Event</h2>
<p>Click somewhere in the document. I will display the name of the element you clicked on.</p>
<h3>This is a heading</h3>
<img border="0" src="smiley.gif" alt="Smiley" width="32" height="32">
<p>This is a paragraph.</p>
<div id="demo"></div>
<script>
function whichElement(e) {
  let targ;
  if (!e) {
    let e = window.event;
  }
  if (e.target) {
    targ = e.target;
  } else if (e.srcElement) {
    targ = e.srcElement;
  }
  let tname = targ.tagName;
  document.getElementById("demo").innerHTML = "You clicked on a " + tname + " element.";
}
</script>
</body>
</html>