
- 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
HTML draggable Attribute
The HTML DOM draggable attribute returns/sets a boolean value specifying if an element is draggable or not.
NOTE − Links and images are draggable by default.
Let us see an example of HTML draggable Attribute −
Example
<!DOCTYPE html> <html> <head> <title>HTML DOM draggable</title> <style> * { padding: 2px; margin:5px; } form { width:70%; margin: 0 auto; text-align: center; } fieldset { min-height: 200px; } input[type="button"] { border-radius: 10px; } .options{ display: inline-block; } #paulaShare { width: 200px; height: 70px; padding: 10px; border: 2px solid black; } #adamShare { width: 200px; height: 70px; padding: 10px; border: 2px solid black; } </style> <script> function allowDrop(dragEvent) { dragEvent.preventDefault(); } function drag(dragEvent) { dragEvent.dataTransfer.setData("Text", dragEvent.target.id); } function drop(dragEvent) { var data = dragEvent.dataTransfer.getData("Text"); dragEvent.target.appendChild(document.getElementById(data)); dragEvent.preventDefault(); } </script> </head> <body> <form> <fieldset> <legend>HTML-DOM-draggable</legend> <div class="options" id="paulaShare" ondrop="drop(event)" ondragover="allowDrop(event)">Paula's Share</div><br> <div class="options"> <p id="optionOne" draggable="true" ondragstart="drag(event)">3/8</p> <p id="optionTwo" draggable="true" ondragstart="drag(event)">5/8</p> </div><br> <div class="options" id="adamShare" ondrop="drop(event)" ondragover="allowDrop(event)">Adam's Share</div> <div id="display">Distribute 8 pizza slices between Adam and Paula in ration 3:5</div> </body> </html>
Output
Before dragging answers −
After dragging answers −
- Related Articles
- How to create a draggable HTML element with JavaScript and CSS?
- How to set whether an element is draggable or not in HTML?
- HTML pattern Attribute
- HTML novalidate Attribute
- HTML maxlength Attribute
- HTML wrap Attribute
- HTML disabled Attribute
- HTML for Attribute
- HTML min Attribute
- HTML disabled Attribute
- HTML disabled Attribute
- HTML min Attribute
- HTML href Attribute
- HTML max Attribute
- HTML enctype Attribute

Advertisements