views:

283

answers:

1

I have a link element where I capture the mousedown event and stop the event from bubbling so that other elements in the page don't get selected. However in firefox (3 & 3.5) when i use the DOM 2 event model It still selects other elements in the page.

I have tested it in opera and it works fine without selecting other elements. Also another weird issue is that if I use the DOM 0 event model it works fine and doesn't select other elements. Is this a bug in firefox or am I just doing it wrong?

Here are the 2 event handlers I used to test

past.addEventListener('mousedown', function (e) {
    e.stopPropagation();
    return false;
}, false);

past.onmousedown = function (e) {
    e.stopPropagation();
    return false;
};
A: 

Have you tried e.preventDefault()? stopPropagation will stop the event handlers on ancestor elements being invoked, but this is not the same thing as preventing the default action from being taken. As the DOM specs don't really specify how mouse events and selection should interact in terms of the event model, it may be one of those areas where one browser does it one way, one does it another, and neither is "right" or "wrong".

NickFitz
Awesome :) So easy!
Alex