Forum Moderators: open
<head>
<style type="text/css">
#div1 {
width:300px;height:200px;
background-color : yellow; padding:15px;
position:absolute; left:50px;top:50px;
}
#div2 {
background-color : green;
width:150px;height:100px;
position:absolute; left:50px;top:50px;
}</style>
<script language="JavaScript" type="text/javascript">
// Moz can return textNodes for target.
// Need to test and return parentNode (element).
getEventSrcElement = window.Event
? function(e){var targ=e.target;return targ.nodeType==1?targ:targ.parentNode}
: function() {return event.srcElement}window.onload = function()
{
var D = document, div1, div2;
div1 = D.createElement('<div>');
div1.id = 'div1';
div2 = D.createElement('<div>');
div2.id = 'div2';
div1.onclick = doSomething;
div1.appendChild(div2);
D.body.appendChild(div1);
}function doSomething(eMoz)
{
var src = getEventSrcElement(eMoz);
if(src!=this) return;
alert(this.id)
}</script>
</head>
<body>