ondragstart Event in JavaScript
ondragstart Event in JavaScript
The ondragstart event fires when the user starts to drag an element or text selection. Links are draggable by default similar to images. We can apply this attribute/event on all HTML elements. There are many event attributes that are used in drag and drop. These are:-
1. Events fired on the draggable target:-
- ondragstart event fired when the user starts to drag an element.
- ondrag event fired when an element is being dragged.
- ondragend event fired when the user has finished dragging the element.
2. Events fired on the drop target:-
- ondragenter event fired when the dragged element enters the drop target.
- ondragover event fired when the dragged element is over the drop target.
- ondragleave event fired when the dragged element leaves the drop target.
- ondrop event fired when the dragged element is dropped on the drop target.
Syntax:-
Its syntax is:- < anyElement ondragstart="my_script" > OR object.ondragstart= function(){my_script} OR object.addEventListener("dragstart", my_script)