Wednesday, December 3, 2008

DOM example 2

<html>
<head>

<script type="text/javascript">
window.onload = function() {
var node = document.getElementById("aassdd");
node.onclick=getEventTrigger;
}

function getEventTrigger(evt)
  {

//  e = e¦¦event;
//alert("The source element's id is: "+ (e.srcElement¦¦e.target).id)

if(evt)
x= evt.target;
else //IE
x = window.event.srcElement;

//  x=e.srcElement¦¦event.target;

  alert("The id of the triggered element: "
  + x.id);
  x = x.nextSibling;
  x = x.lastChild;
  alert("The id of the triggered element: "
  + x.nodeValue);

  }
</script>

</head>
<body >

<p id="aassdd" onclick="getEventTrigger">Click on this paragraph. An alert box will show which element triggered the

event.</p><p id="aa" onclick="getEventTrigger">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.</p><p id="dd"

onclick="getEventTrigger">Click on this paragraph. An alert box willshow which element triggered the event.</p>

</body>
</html>

No comments: