JavaScript - Dynamically Remove List When Drag
Submitted by razormist on Thursday, October 24, 2019 - 14:43.
In this tutorial we will create a Dynamically Remove List When Drag using JavaScript. This code will dynamically delete the list when you drop it in the drop zone. The code use JavaScript drag and drop feature in order to dynamically remove the list by binding an id in the ondragstart() event. A user-friendly program so that you can modify and understand it without an ease.
We will be using JavaScript as a server-side scripting language that interpret a program to extend a whole new level of HTML experience. A scripting language that use in different ways that provide a whole level of experience when visiting a website.
There you have it we successfully created a Dynamically Remove List When Drag using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting started:
First you have to download bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-5">
- <ul>
- </ul>
- </div>
- <div class="col-md-7">
- <img src="image/trash.png" height="200" width="200" ondrop="drop(event)" ondragover="dragOver(event)"/>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will delete a list when drop in the target zone. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.- function dragOver(e){
- e.preventDefault();
- }
- function drop(e){
- e.preventDefault();
- var data = e.dataTransfer.getData("data");
- var el = document.getElementById(data);
- el.parentNode.removeChild(el);
- alert("Deleted an item!");
- }
- function drag(e){
- e.dataTransfer.setData("data", e.target.id);
- }
Add new comment
- 43 views