0

When I press and move the mouse on a text selection in the browser, the default behavior is to drag the selected text? How does it work?

  1. Can I add an event listener on the document.getSelection() or something like that, if I want to change the default behavior rather than prevent it.

  2. Or if there is an event listener registered on the document to handle it, how does the browser check the dragstart event's target is the selected text?

j08691
  • 204,283
  • 31
  • 260
  • 272
Yuchu Luo
  • 1
  • 1

1 Answers1

0

There exists a DOM ondrag Event which you can use to detect if text or any other HTML element is being dragged. The event is described on w3schools. But you can't change the browser's default behavior on selected text.

An example for a draggable text:

<p draggable="true" ondrag="alert(event)">Drag me!</p>
Maxir
  • 13
  • 4