The HTML ondragstart attribute is an event handler that triggers a script to execute when a user starts dragging an HTML element or a text selection within an element.
Definition and Usage
➔ This event signals the start of a drag-and-drop operation.
➔ In the ondragstart event you typically use the event.dataTransfer.setData() method to store the data that will be transferred during the drag operation and that data will be available on the drop target.
➔ If the element is not draggable by default, the element must have draggable="true" set to enable dragging.
➔ Events are fired on draggable items that will be dragged to the target.
- ondragstart - This is fired when the user begin to drag an element.
- ondrag - This is fired when an element is being dragged.
- ondragend - This is fired when the user has complete dragging the element.
➔ Events fired on the drop targets where the item can be dropped.
- ondragenter - This is fired when the dragged element enters the drop target.
- ondragover - This is fired when the dragged element is over the drop target.
- ondragleave - This is fired when the dragged element leaves the drop target.
- ondrop - This is fired when the dragged element is dropped on the drop target.
Applies to
This attribute can be used on the following element.
| Attribute | Element |
|---|---|
| ondragstart | All visible elements |