S
sriram.nandakumar
Hi there..
I have this piece of code to basically understand the event model in
IE.
<html>
<head>
<title>Events</title>
<script>
function callMe(){
alert(this.nodeName)
};
function setEvents(){
document.attachEvent('onclick', callMe);
document.body.attachEvent('onclick', callMe);
var x = document.all;
if (x){
for(var i = 0; i<x.length; i++){
if (x.attachEvent){
x.attachEvent('onclick', callMe);
}
};
}
}
</script>
</head>
<body onload="setEvents()">
<h1>Events</h1>
<p > The IE event model is called Event bubbling which
prmarily works from most-specific to least-specific object</p>
<input type="button" value="click me"></input>
</body>
</html>
While a similar flavored code works works 'as intended' in Mozilla, in
IE the event callMe there are some subtle differences.
If you notice, in the method callMe I am trying to figure out which is
the node that triggered the onclick event. In Firefox I get the correct
node name whereas in IE (using 7.0 beta and checked the same in 6.0
also) I get 'undefined'.
The event object also offers no assistance to say which is the object
that is throwing up the event (or probably I am not aware of it). The
closest thing that I could find was event.srcElement which basically
points to the originating object only.
Given this my query is - When assigning methods dynamically, as events,
to a set of objects, is there any mechanism to find out which is the
object that is executing the method?
Thank you.
I have this piece of code to basically understand the event model in
IE.
<html>
<head>
<title>Events</title>
<script>
function callMe(){
alert(this.nodeName)
};
function setEvents(){
document.attachEvent('onclick', callMe);
document.body.attachEvent('onclick', callMe);
var x = document.all;
if (x){
for(var i = 0; i<x.length; i++){
if (x.attachEvent){
x.attachEvent('onclick', callMe);
}
};
}
}
</script>
</head>
<body onload="setEvents()">
<h1>Events</h1>
<p > The IE event model is called Event bubbling which
prmarily works from most-specific to least-specific object</p>
<input type="button" value="click me"></input>
</body>
</html>
While a similar flavored code works works 'as intended' in Mozilla, in
IE the event callMe there are some subtle differences.
If you notice, in the method callMe I am trying to figure out which is
the node that triggered the onclick event. In Firefox I get the correct
node name whereas in IE (using 7.0 beta and checked the same in 6.0
also) I get 'undefined'.
The event object also offers no assistance to say which is the object
that is throwing up the event (or probably I am not aware of it). The
closest thing that I could find was event.srcElement which basically
points to the originating object only.
Given this my query is - When assigning methods dynamically, as events,
to a set of objects, is there any mechanism to find out which is the
object that is executing the method?
Thank you.