Get event source element

Description

The following code shows how to get event source element.

Example


<html>
<head>
<script language="JavaScript">
  function checkBold() {<!--  www .j  a v  a 2 s  . c o  m-->
    var thistag, parentTag;
    thistag = window.event.srcElement.tagName;
    parentTag = window.event.srcElement.parentElement.tagName;

    if (thistag == "H1" && parentTag == "BODY") {

      if (document.all(window.event.srcElement.id + "p").style.display == "none") {
        document.all(window.event.srcElement.id + "p").style.display = "";
      } else {
        document.all(window.event.srcElement.id + "p").style.display = "none";
      }
    }
  }
</script>
</head>
<body onclick="checkBold()">
  <h1 id="head1">Heading One</h1>
  <p id="head1p" style="display: none">111111111111111</p>
  <h1 id="head2">Heading Two</h1>
  <p id="head2p" style="display: none">22222222</p>
  <h1 id="head3">Heading Three</h1>
  <p id="head3p" style="display: none">3333</p>
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window