0

This is a follow up question to: Can you emulate the left-mouse button selection in JQuery?

The solution works fine in IE9, Firefox and Chrome, but it IE8 still does the browser's default selection i.e. highlighting the text.

isMouseDown = false

$('body').mousedown(function (e) {
    e.preventDefault(); // Prevent default behavior
    isMouseDown = true;
})
.mouseup(function (e) {
    e.preventDefault(); // Prevent default behavior
    isMouseDown = false;
});

$(".div").live("mouseenter", function (e) {
    e.preventDefault(); // Prevent default behavior
    if (isMouseDown) {
        $(this).toggleClass("selected");
    }
});

So I assume e.preventDefault() is not working. Is there a way to fix this?

Community
  • 1
  • 1
xsl
  • 17,116
  • 18
  • 71
  • 112

1 Answers1

0

Found the solution myself. You have to prevent the default in mousemove too:

// Because IE8 won't get it without this...
$(".module").mousemove(function (e) {
    if ($.browser.msie) {
        e.preventDefault();
        return false;
    }
});
xsl
  • 17,116
  • 18
  • 71
  • 112