91-9990449935 0120-4256464 |
HTML Drag and DropHTML Drag and Drop (DnD) is a feature of HTML5. It is a powerful user interface concept which is used to copy, reorder and delete items with the help of mouse. You can hold the mouse button down over an element and drag it to another location. If you want to drop the element there, just release the mouse button. If you want to achieve the Drag and Drop functionality in traditional HTML4, you must either have to use complex JavaScript programming or other JavaScript frameworks like jQuery etc. Events for Drag and Drop feature
HTML5 Drag and Drop ExampleLet's see an example of HTML 5 drag and drop feature. To understand this example, you must have the knowledge of JavaScript.In the above example, we have used ondrop and ondragover events on div element, and ondragstart event on img tag. Test it NowOutput: Drag the javatpoint image into the rectangle: Note: MouseEvent is not fired during drag operation.Stages during Drag and Drop operations1) Make an element draggable If you want to make an element draggable, set the draggable attribute to "true" on the element. For example: 2) What to drag: Use ondragstart and setData () methods. Specify what should happen when the element is dragged. 3) Where to Drop: Use ondragover event. 4) Do the Drop: Use ondrop event. Supporting Browsers
Next TopicHTML Marquee
|