Сообщение от danik.js
|
В обработчике this указывает на элемент, на котором навешан обработчик,
|
только не в ИЕ.
<head>
<meta charset="utf-8">
<title>Документ без названия</title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
background-color: #0000FF;
}
#apDiv2 {
position:absolute;
width:155px;
height:73px;
z-index:1;
background-color: #FFFF00;
left: 25px;
top: 16px;
}
</style>
</head>
<body>
<div id="apDiv1">
<div id="apDiv2">Click</div>
</div>
<script>
if (document.attachEvent) document.getElementById('apDiv1').attachEvent('onclick',function(){alert(this.id)});
else document.getElementById('apDiv1').addEventListener('click',function(){alert(this.id)},false);
</script>
</body>