ondrag Event in JavaScript
ondrag Event in JavaScript
The ondrag event fires when an element or text selection is being dragged. Links are draggable by default similar to images. We can apply this attribute/event to all HTML elements. There are many event attributes that are used in drag and drop. These are:-
1. Events fired on the draggable target are:-
- 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 ondrag="my_script" > OR object.ondrag= function(){my_script} OR object.addEventListener("drag", my_script)