can't cancel event in IE

D

dave

What I am attempting to do is cancel an event in IE inside of my event
handler, but the handler keeps getting called:


for example if I do
<div id="foo">
<div id="test">test text</div>
</div>

and assign an event by doing:
document.attachEvent("onclick",functionName)

IE seems to be firing the event twice. Is there a way to stop it?

the function looks like:

function functionName(e){
if (!e) e = window.event; // IE event model
//do something then:

if (e.stopPropagation) e.stopPropagation(); // DOM Level 2
else e.cancelBubble = true; // IE
}

// Now prevent any default action.
if (event.preventDefault) event.preventDefault(); // DOM Level
2
else event.returnValue = false;

}
 
T

Thomas 'PointedEars' Lahn

dave said:
What I am attempting to do is cancel an event in IE inside of my event
handler, but the handler keeps getting called:


for example if I do
<div id="foo">
<div id="test">test text</div>
</div>

and assign an event by doing:
document.attachEvent("onclick",functionName)

IE seems to be firing the event twice. [...]

Your code looks OK to me (although your feature test could be better).
Could it be that you call document.attachEvent() twice? Also note that
`document' does not refer to an element object.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top