
- 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
Execute a script when an element has been dragged to a valid drop target in HTML?
When an element has been dragged in HTML to a valid drop target, the ondragenter attribute fires.
Example
You can try to run the following code to implement the ondragenter attribute −
<!DOCTYPE HTML> <html> <head> <style type = "text/css"> #boxA, #boxB { float:left;padding:10px;margin:10px; -moz-user-select:none; } #boxA { background-color: #6633FF; width:75px; height:75px; } #boxB { background-color: #FF6699; width:150px; height:150px; } </style> <script type = "text/javascript"> function dragStart(ev) { ev.dataTransfer.effectAllowed = 'move'; ev.dataTransfer.setData("Text", ev.target.getAttribute('id')); ev.dataTransfer.setDragImage(ev.target,0,0); return true; } </script> </head> <body> <center> <h2>Drag and drop HTML5 demo</h2> <div>Try to drag the purple box around.</div> <div id = "boxA" draggable = "true" ondragstart = "return dragStart(ev)"> <p>Drag Me</p> </div> <div id = "boxB">Dustbin</div> </center> </body> </html>
- Related Articles
- Execute a script when an element is being dragged over a valid drop target in HTML?
- Execute a script when the element is being dragged in HTML?
- Execute a script when the dragged element is being dropped in HTML?
- Execute a script when a page has unloaded in HTML?
- Execute a script when a mouse pointer moves over an element in HTML?
- Execute a script when the element is invalid in HTML?
- Execute a script when the element loses focus in HTML?
- Execute a script when the element gets focus in HTML?
- Execute a script when a mouse button is released over an element in HTML?
- Execute a script when a mouse pointer moves out of an element in HTML?
- Execute a script when an error occurs in HTML?
- Execute a script when the media has started playing in HTML?
- Execute a script when the cue changes in a element in HTML?
- Execute a script when the user pastes some content in an element in HTML?
- Execute a script when the element is being clicked in HTML?

Advertisements