Event Bubbling (Firefox) : Event Handler « Event « JavaScript Tutorial






<html>
<head>
<title>Event Bubbling</title>
<script type="text/javascript">
function mouseDown(nsEvent) {
  var theEvent = nsEvent ? nsEvent : window.event;
  var locString = "X = " + theEvent.screenX + " Y = " + theEvent.screenY;
  var theSrc = theEvent.target ? theEvent.target : theEvent.srcElement;
  document.write(locString + " " + theSrc);
}

document.onmousedown=function (evnt) {
   var theEvnt = evnt? evnt : window.event;
   document.write(theEvnt.type);
}


window.onload=function () {
   document.getElementById("first").onmousedown=mouseDown;
   document.getElementById("second").onmousedown=function () {
      document.write("Second event handler");
   }
}

</script>

</head>
<body>
<div id="first" style="padding: 20px; background-color: #ffff0; width: 150px">
  <div id="second" style="background-color: #ff0000; width: 100px; height: 100px"></div>
</div>
</body>
</html>








15.12.Event Handler
15.12.1.Add event handler listener to document
15.12.2.Preventing Bubble and Capture
15.12.3.Register mouse down event(IE)
15.12.4.Event Handlers and this
15.12.5.Event Bubbling (Firefox)
15.12.6.Capturing events
15.12.7.Add event listener to form
15.12.8.Add event listener to elements in a form
15.12.9.Bubble up events (Firefox)
15.12.10.Inline DOM Event Registration