
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Which event occurs in JavaScript when the dragging of an element begins?
The ondragstart event triggers when dragging of an element begins.You can try to run the following code to learn how to implement ondragstart JavaScript event −
Example
Live Demo<!DOCTYPE HTML> <html> <head> <style> .drag { float: left; width: 100px; height: 35px; border: 2px dashed #876587; margin: 15px; padding: 10px; } </style> </head> <body> <div class = "drag" ondrop = "drop(event)" ondragover = "dropNow(event)"> <p ondragstart = "dragStart(event)" ondragend = "dragEnd(event)" draggable = "true" id = "dragtarget">Drag!</p> </div> <div class = "drag" ondrop = "drop(event)" ondragover = "dropNow(event)"></div> <div id = "box"></div> <p>Drag the left box to the right or drag the right box to the left.</p> <script> function dragStart(event) { event.dataTransfer.setData("Text", event.target.id); } function dropNow(event) { event.preventDefault(); } function dragEnd(event) { document.getElementById("box").innerHTML = "Dragging ends!"; } function drop(event) { event.preventDefault(); var data = event.dataTransfer.getData("Text"); event.target.appendChild(document.getElementById(data)); document.getElementById("box").innerHTML = "The element dropped successfully!"; } </script> </body> </html>
- Related Articles
- Which event occurs in JavaScript when an element is dragged completely?
- Which event occurs in JavaScript when an element is getting dragged?
- Which event occurs in JavaScript when an element's content is cut?
- Which event occurs in JavaScript when an element's content is pasted?
- Which event occurs in JavaScript when a dragged element is dropped?
- Which event occurs in JavaScript when an element is content is copied to clipboard?
- Which event occurs in JavaScript when the dragged element is over the target?
- How to detect the dragleave event in Firefox when dragging\noutside the window with HTML?
- Which is the event when the browser window is resized in JavaScript?
- How to get attribute of an element when using the 'click' event in jQuery?
- How to set the minimum number of lines for an element that must be left at the bottom of a page when a page break occurs inside an element with JavaScript?
- How to add an event handler to the specified element in JavaScript?\n
- How to add an event handler to an element in JavaScript HTML DOM?
- Deleting occurrences of an element if it occurs more than n times using JavaScript
- How to trigger the onchange event on input type=range while dragging in Firefox?

Advertisements