Skip to content Skip to sidebar Skip to footer

JQuery PreventDefault And IE8 Clarification

I have been trying to understand why sometimes IE8 doesn't like PreventDefault and why sometimes it seems to be OK (no errors). From what I have read, including here at SO is that

Solution 1:

Yes, your understanding sounds correct. Also, if you're using a "DOM0" event handler (e.g. someElement.onclick = function(e) { ... }), there is a simpler way to prevent the browser default behaviour that works in all browsers that support events: return false.

var someElement = document.getElementById("someElementId");
someElement.onclick = function(e) {
    // Do some stuff
    return false;
};

However, in this case, the event is not passed to the event handler in IE <= 8 and you have to get it from window.event instead.


Post a Comment for "JQuery PreventDefault And IE8 Clarification"