

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a draggable paragraph in HTML5
Use the draggable attribute to create a draggable paragraph. Enable or Disable the drag using the values true and false.
Example
You can try to run the following code to implement draggable element and drag an element −
<!DOCTYPE HTML> <html> <head> <style> .drag { float: left; width: 100px; height: 75px; border: 1px dashed #876587; margin: 15px; padding: 10px; } </style> </head> <body> <div class = "drag" ondrop = "drop(event)" ondragover = "dropNow(event)"> <p ondragstart = "dragStart(event)" ondrag = "draggingNow(event)" draggable = "true" id = "dragtarget">This is demo paragraph to be dragged!</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 draggingNow(event) { document.getElementById("box").innerHTML = "Dragged successfully!"; } function dropNow(event) { event.preventDefault(); } 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 Questions & Answers
- Create a hidden paragraph in HTML5
- Create a paragraph with a right-to-left direction in HTML5
- How to create a draggable legend in Matplotlib?
- How to create a draggable HTML element with JavaScript and CSS?
- HTML draggable Attribute
- Create a pattern with HTML5 Canvas
- How to add a paragraph in HTML?
- Create a text inside circles in HTML5 Canvas
- Create self-contained content in HTML5
- Indent the first line of a paragraph in CSS
- How to create a transformation matrix with HTML5?
- Indent the text of a paragraph with CSS
- Align the text of a paragraph with CSS
- Add some emphasis to a paragraph with Bootstrap
- Adding paragraph tag to substrings within a string in JavaScript
Advertisements