Reputation: 369
I am fighting this issue for a while now and all my searches leads to use preventDefault() in my onmousedown listener (to prevent text selection), but when I do so, it is also disabling my dragging (can't drag elements even if they have the draggable="true" attribute).
what is the best way to allow dragging elements (using the attribute draggable="true") and when dragging them and hovering with the mouse over some text (p, h1 ,h2...) prevent the text background form being blue (you know - the default when clicking and marking text)
Thanks. Jim.
Upvotes: 2
Views: 2620
Reputation: 718
Found the solution.
Just add onmousedown="mouseDown()"
to your element and this method:
function mouseDown() {
window.getSelection().removeAllRanges();
}
This will unselect all previous selections and only highlight the current element being dragged.
Upvotes: 1