js draggable

<script>
  var dragged;

  /* events fired on the draggable target */
  document.addEventListener("drag", function(event) {

  }, false);

  document.addEventListener("dragstart", function(event) {
    // store a ref. on the dragged elem
    dragged = event.target;
    // make it half transparent
    event.target.style.opacity = .5;
  }, false);

  document.addEventListener("dragend", function(event) {
    // reset the transparency
    event.target.style.opacity = "";
  }, false);

  /* events fired on the drop targets */
  document.addEventListener("dragover", function(event) {
    // prevent default to allow drop
    event.preventDefault();
  }, false);

  document.addEventListener("dragenter", function(event) {
    // highlight potential drop target when the draggable element enters it
    if (event.target.className == "dropzone") {
      event.target.style.background = "purple";
    }

  }, false);

  document.addEventListener("dragleave", function(event) {
    // reset background of potential drop target when the draggable element leaves it
    if (event.target.className == "dropzone") {
      event.target.style.background = "";
    }

  }, false);

  document.addEventListener("drop", function(event) {
    // prevent default action (open as link for some elements)
    event.preventDefault();
    // move dragged elem to the selected drop target
    if (event.target.className == "dropzone") {
      event.target.style.background = "";
      dragged.parentNode.removeChild( dragged );
      event.target.appendChild( dragged );
    }
  }, false);

</script>

4
1
EnglishAdam 110 points

                                    &lt;p draggable=&quot;true&quot;&gt;This is a draggable paragraph.&lt;/p&gt;

4 (1 Votes)
0
3.44
8

                                    &lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;title&gt;DRAG_AND_DROP&lt;/title&gt;
    &lt;style&gt;
  	body{
    background-color: aquamarine;
}
.whiteBox{
    height: 250px;
    width: 250px;
    background-color: rgb(55, 238, 245);
    margin: 10px;
    display: inline-block;
    border: 2px solid red;
}
.imgBox{

    display: flex;
    background-image: url(&quot;image.jpg&quot;);
    height: 230px;
    width: 230px;
    position: relative;
    top: 10px;
    margin:0 auto;
    cursor: pointer;

}
.imgBox1{

    display: flex;
    background-image: url(&quot;image.jpg&quot;);
    height: 230px;
    width: 230px;
    position: relative;
    top: 10px;
    margin:0 auto;
    cursor: pointer;

}
.hold{
    border: 2px dashed rgb(118, 182, 0);
}
.hide{
    display: none;
}
.dragenter{
    background: rgb(221, 115, 96);
    border-color: green;
    border-style: groove;
}
  	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div class=&quot;whiteBox&quot;&gt;
        &lt;div class=&quot;imgBox&quot; draggable=&quot;true&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;whiteBox&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;whiteBox&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;whiteBox&quot;&gt;&lt;/div&gt;
    &lt;script&gt;
  	console.log(&quot;D&amp;D&quot;);

let imgBox = document.querySelector(&quot;.imgBox&quot;);
let whiteBoxes = document.querySelectorAll(&quot;.whiteBox&quot;);

imgBox.addEventListener(&quot;dragstart&quot;, (e) =&gt; {
  console.log(&quot;DRAG STARTED&quot;);
  e.target.className += &quot; hold&quot;;
  setTimeout(() =&gt; {
    e.target.className += &quot; hide&quot;;
  }, 0);
});
imgBox.addEventListener(&quot;dragend&quot;, (e) =&gt; {
  console.log(&quot;DRAG ENDED&quot;);
  e.target.className = &quot;imgBox&quot;;
});

for (whiteBox of whiteBoxes) {
  whiteBox.addEventListener(&quot;dragover&quot;, (e) =&gt; {
    e.preventDefault();
    // console.log(&quot;gj&quot;)
  });
  whiteBox.addEventListener(&quot;dragenter&quot;, (e) =&gt; {
    e.target.className += &quot; dragenter&quot;;
  });
  whiteBox.addEventListener(&quot;dragleave&quot;, (e) =&gt; {
    e.target.className = &quot;whiteBox&quot;;
  });
  whiteBox.addEventListener(&quot;drop&quot;, (e) =&gt; {
    let answer= confirm(&quot;Do you really want to move it&quot;)
    console.log(answer)
    if(answer){
        e.target.append(imgBox)}
        else{
            e.target.className = &quot;whiteBox&quot;;
       
    }
  });
}

  	&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

3.44 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
code for drag and drop draggable in htnml understanding drag and drop Drag and drop editor to do drag and drop draggable items in js how drag and drop html html draggable w3schools html dragger drag and drop ansys make html element draggable html drag how to make element in javascript draggable draggable div w3schools html draggable and droppable query drag and drop draggable html 5 how to make an element draggable in html5 creating drag in js why cant i drag and drop How to drag and drop create html make an element draggable with javascript draggable elements html draggable elements hml draggable element javascript make an element draggable in js make an element draggable in html5 how to use the draggable attribute html javascript make a div draggable drag and drop event drag javascript draggable buble drag and drop html site make eleemnt draggable javascript Drag and drop method how to make a draggable div javascript drag and drop data structure how to make a drag and drop ediot two way drag and drop drag drop w3 drag in javascript js add draggable make draggable item html js draggable element html drag and drop website drag javascript draggable html attribute drag and drop items what if i make draggable = false will drag and drop work html for draggab;e How do I add drag and drop? you can use drag and drop method to draggrable js drag and drop display on drag drag and drop instructions html draggabble html element draggable how does drag work draggable w3 js draggable image how to handle drag and drop in html drag and drop w3 dynamic drag and drop how to create a draggable html element drag and drop fragen what is drag drop drag and drop sample how to do drag and drop in igTree how to set draggable in html css js draggable drag and drop dragleave make elements draggable html how to make something dragable in js make a div draggable in html drag and drop brows draggable items js best way to drag and drop drag and drop data html make element draggable how to make draggable objects in html html javascript draggable elements order by drag and drop how to implement drag and drop in html5 How to make draggable div in html how to use draggable attribute in html draggable bar html w3schools draggable how to add draggable in javascript draggable.min.js Drag and drop htm drag and drop backend drag and drop ordering creating html css using drag drop drop and drag html html code to drag and drop javascript set element draggable drag with javascript html draggable div w3school drag and drop IOT drag and drop meaaning draggable list js js draggable element make elemnt draggable js drag and drop architectur draggable with plain js drag and drop demo html drag w3school drag and drop correct Implement Drag and Drop how to create html statement drag and drop Drag and drop is a technique to drag drop tutorial drag and drop drop js html draggable api image drag and drop build drag and drop in html how to make elements draggable in html drag @ drop making drag and drop work drag and drop dynamic draggable and droppable in html making an element draggable using js Drag and drop proplem w3 draggable div drag and drop drop css drag and drop[ drag and drop defold draggable() javascript draggable example drag and drop design example draggable in html draggable .js javascript create draggable window oden drag drop css draggable how to make drag-and-drop in html html draggable div drag and drop effect create drag and drop html draggable css make an element draggable javascript drag and drop html w3schools drag and droptodo how to make element draggable in html5 html draggable element buble draggable html html5 draggable div drag &amp; drop elements drag and drop ide html drop and drag drag and drop html example d3 drag and drop example how to make an element draggable js create drag and drop drag and drop possible using HTML5 and how make an html element draggable javascript html drag-and-drop how to make draggable element js drag and drop table drag and drop options make drag and drop html javascript draggable element drag androp drag'n drop drag'ndrop drag and drop elements css froLO drag and drop drag and drop code dnd drag and drop code drag and drop sorting Drag and Drop in a box drag and drop operation css make drag and drop drag and drop area drag &amp; drop html drag and drop example in html css drag and drop function drag and drop to html code drag and drop in hmlt draggable windows javascript html draggable elements drag and drop web drag and drop design implement drag and drop javascript js draggable list make element draggablejs drop and drag javascript create draggable element drag and drop html5 example drag and drop in html5 HTML5 drag and drop example drag and drop definition drag and drop formula masory drag and drop drag and dropp draggable js demo create html with drag and drop html simple drag drop what created drag and drop create draggable element javascript dnd drag and drop make a drag and drop Drag and Drop codehs draggable html drag and drop plugin how to make an element draggable javascript html drag and drop vs javascript drag and drop how to add drag and drop in html drag and drop line using drag and drop menu Drag and Drop drag $&amp; drop drag drop imbriqu&eacute; create html by drag and drop draggable in js plain javascript draggable javascript make item draggable drag an drop in html drag and droping drag &amp; drop website drag and drop implementation drag and srop d3 drag and drop drag and drop d3 html drag drop html drag and droper drag and drop ui library javascript make element draggable draggable.js how to use it simple js drag drop Drag and drop. drag and drop simple example draggable elements javascript draggable in javascript how to make a drag in javascript dragula drag and drop js drag drag and drop to code drag and drop in anmtd javascript drag example html5 draggable drag and drop box javascript make draggable How to add drag and drop in HTML? javascript drag drag and drope draggable js documentation style draggable javascript draggable js examples html draggable example html draggable drag and drop position how to make a drag and drop in html drag and drop select how to make a drag and' drop in html js make element draggable simple drag drop how can drag and drop editor use JS libraries html5 drag and drop native dargand drop api javascript draggable on drop drag and drop divs how to set different style while drag in html css javascript draggable library react drag and drop javascrp draggable how to drag and drop elements using js drag and drop with value dragulla js draggable js java script drag and drop &quot;draggable.js&quot; div drag and drop in a bar html html draggable sampe w3 html draggable item -drop php drag and drop how to drag and drop in html drag and drop events example javascript js drag and drop library draggable dib drag and drop css html html on draging draggable.min drag and drop div drag and drop p&aring; dansk JAVASCipt drag and drop drag and drop jquery example drap and drop a file w3schools create a draggable element in javascript JAVASCRIPT dragable component framework drag and drop image html where go the dragged element css add drag and dorp html5 drag html 5 drag html5 drag and drop list example draggable div element drag and drop css html website datatransfer javascript w3schools make drag and drop boxes html drag and drop function in javascript Drag'n'drop css div drag and drop drag n droo drag and drop box html interact drag and drop .draggable javascript drag drop w3schools drag and drop example website drag and drop in website html 5 drag and drop draggable w3schools drag in drop drag items css drag and drop file w3schools image can drag html image drag and drop javascript drag and drop layout making html php drag and drop boxes html html object drag and drop drag drop events javascript draggable div library drag and drop php html drag and sort drag and drop example html js movable gui javascript drag drop html5 drag and drop html blocks javascript drag and drop events jquery input draggable drag and scroll javascript js drag events how to make dragable element drag and drop outside browser drag and drop functionality dragdrop.js alpine drag and drop drag and drop jsfiddle drag and drop drag css css for drag and drop javascript dragn and drop drag and drop on image html element draggable javascript drag and drop drag and drop js draging event in js on drag function jquery .draggable add drag to dom elements alpine js drag and drop drag and move elements in html drag and move html drag and drop html elements javascript native drag and drop simple drag and drop js js drag and drop drag and ndrop css drag drop js dragula js drag and drop jq drag and drop javascript drug and drop js how to drag and drop in javascript drag and drop to do js library for dragging a box over an image js library for dragging a box over a image how to support drag and drop draggable api drag-drop image Responsive drag and drop jquery code drag and drop drag and drop js api drag n drop js api enable drag on html ES6 drag and drop html5 drag and drop image drag html drag drop div how to drag php tract drag and drop drag and drop drag and drop dom elements :dragging css javascript drag and drop objects js html drag and drop drag and drop text in html drag on html how to make a input to dragw on html bootstrap drag and drop file upload w3schools draggable stuff in javascript how to create drag and drop area using html and js drag drop javascript fdrag and drop js html5 allows element to dragged and dropped inside an HTMLpage which needs to be called to prevent the brower default drag and drop handling of data dragable with js js drang and drop make a div draggable vis js drag and drop drag and drop a container element html javascript drag and drop example with dropdown html drop image javascript draggable number picker drago and drop items draggable.js grabbable.js how to drag and drop in hrml css how drag and drop data in html how drag and drop item in html how to drag and drop div how to restrict the area of drag and drop in html drag &amp; drop ho to make drag and drop in HTMl movable div drag and drop events js html drag and drop api tutorial jquery html5 list drag and drop example how to implement drag and drop javascript implement drag and drop html drag and drop modify drag and drop elements drag and drop to code javascript library js drop event drag events draggable div in jquery drag and drop in jquery drag and drop on div draggable element js javascript event drag and drop drag and drop items javascript javascript dragable make div draggable jquery jquery click and drag drag and drop html5 draggable elements js how to drag and drop a div in html make element dragable how to make html drag and drop draggable element javascript how to drag and drop drop page css and html page drop html click and drag css technique drag and drop using jaavascript draggable.js tutorial javascript draggavble drag and drop a image in java script place a div at drag place create table on drag and drop event javascrip drag and drop js code to a drug and drop w3schools drag and drop html5 drag drop api draggable function html drag and drop div html drag and drop html drop module from javascript proyect css on drag html dnd example javascript drag panel LIBRARY code for drag and drop javascript html drag component hmtl drag and drop javascript exercises html5 drag and drop mouse events make a div droppable how to make drag and drop with html javascript drag and drop api detect drag and drop css drag drop api html5 how to drag and Drop html js drag and drop item drag&amp;drop html drag and drop file upload w3schools js drag and drop events draw e drop js javascript drag and drop items Drag And Drop Script html css drag n drop div how to make a drag and drop with javascript drag and drop js code drggalbe dic js draggable js library drag and drop library API Drag and drop js drag and drop element js drag drop menu html js drag and drop js drag and drop sort animation drag and drop js library javascript drag and drop example drag and drop example in javascript board drag nad drop javascirpt drag and drop example in javascript drag drop js framework drag drop framework html css drag and drop show earth draggable area html5 html make an element receive drop drag and drop image in html js drag and drop elements js javascript drag and drop bootstrap drag and drop interface javascript drag and drop fields html code on drop element html drag-drop html drag and drop box drag and drop links to create html page drag and drop links to html drag and drop text to html library drag js drag and drop html and css codes html drag drop api drag drop append value to drop html element drag n drop code file drag and drop html 5 drag drop events w3school drag drop drag and drop events how to make div droppable drag drop images grag and drop html css div drag and drop drag n drop how to create drag and drop elements in html drag and drop using css drag n drop js dragdrop html what websites use drag and drop javascript js drag n drop js div draggable dragdrop js w3c html drag img into html on drop javascirpt drag drag and drop field html drag and drop image in html drop over image in html drag and drop w3c drag and drop example html drag css can we develop html with drag and drop drag in js drag images html drag drop css make drag and drop javascript how to create drag and drop in html draggable js tutorial html drag and drop file w3schools drag an html drag and drop css javascript drag and drop to html draggble js drag drop in html5 examples jquery drag and drop configurator how to drag and drop image in html into a div drag and drop area html html5 drag and drop api drag-and-drop components in javascript drag.js example how to make drag and drop in html how to use drag and drop html simple html5 drag and drop drag and drop html 5 HTML Drag and Drop examples how to drag n drop element js jquery droppable code example w3schools drag and drop form in html5 drag and drop tag in html5 how to create drag and drop in the DOM drag and drop a drop and darg api js draggable library drag an drop image css html drag and drop effects in html5 drag and drop html css drag and drop in css .draggable( js dragable drag and drop example draggable js example drag and drop image html drop image html drag drop html dragzone allow widgets/draggable.js javascript drag drop guide lines for 4 sides javascript html drag drop guidelines for 4 sides javascript html drag guidelines for 4 sides javascript html drag guidelines for 4 sides html5 drag guid for 4 sides htnl5 drag and drop div javascript drag and drop tutorial html file drag and drop draggable div javascript drag n drop javascript web drag and drop drag and drop object moving js library image drage and drop html drag and drop example text field html drag and drop example textfield css drag and drop js drag event drag and drop html javascript drag and drop html div drag and drop image in javascript drag and drop set value drag and drop image javascript HTML Drag and Drop API drag and drop html js image drag and drop with css html5 drag drop drag and dop css js library drag and drop css drag drop drag and drop to css drag and drop w3 school js movable areas raggable DIV Element how drag and drop websites works in javascript drag and drop css div drag and drop drag div draggable drag and drop features drag and drop example in html5 javascipt drag and drop ui draggable divs drag img drag and drop image example page DRAG AND DROP WITH HTML HTML Drag and Drop API example bootstrap drag drop add dragging of elements html html dop itens element drag and drop w3 js css draggable drag api set allowdrop drag property with jquery Simple Drag and Drop html drag text drag and drop to html web drag library dragging dom elements drag and drop w3schools drag and drop v3schools .drag javascript javascript for drag and drop drag and drop html javascript css drag and drop implement drag and drop n html read drag drop a href drop event link html javascript function html javascript drag and drop simple code drag and drop task draggable js jquery drag and drop example drag and drop element js jquery drag and drop html drag and drop eventa drag and dropjavascript how to make drag and drope option javascript .draggable html drag and drop example drag and drop bootstrap js draggable items drap and drop fowers jquery drag and drop in js drag and drop examples drag and drop examples javascript drag and drop api javascript html/scc drag and drop drag and drop examples using javascript bootstrap drag and drop html5 drag and drop image get and display example javascript draging and drop drag div drag drop page how to write something after dropend html5 draggable div drag and drop javascript demo drag and drop API js js library drag drop html css drag and drop drag and drop css drag and drop framework magnetic drag drop effect example in javascript html drag and drop list javascript drag drop draggable how to drag and drop using javascript drag and drop tutorial javascript drag item html drag drop draggable button jquery drag n drop jquery from div drag to droplist drag and edit element draggable html5 drag and drop htmlk drop and drag js drag and drop effect css drag and drop images drop html html5 drag and drop drag library js js draggable div drop image example html5 css3 drag and drop builder in javascript html5 css3 drag and drop drag and drop in html draggable html5 drag/drop api drag and drop library js droppable html how to make a drag and drop system in javascript how to make drag and drop image in html drag and drop in bootstrap drag drop comment html javascript draggable div How to make drag and drop in Javascript? drag and drop text box in java javascript html5 drag drop example drag drop html html drag and srop example drag &amp; drop js drag and drop jquery drag and drop in javascript create html drag and drop drag and drop api drag and drop html drag and drop javascript html drag and drop animation js html drag and drop css drag drag and drop elements in html css html crag and drop drag and drop php js drag and drop dropdown draggable arbo js drag drop library javascript dragable handler js drag image to different buckets javascript movable content html drag and drop blocks javascript open srouce drag and drop selection html library javascript free drag and drop js libary for draggable tiles node js drag and drop drag and drop UI component js dragable js detect drag and drop nodejs drag javascript library prebuilt html drag drop screen create html drag and drop page javascript drag and drop library js drag drop library ranger draggable js draggable js drag and drop javascript library using draggable js javascript drag js javascript draggable jquery draggable js plugin drag drag js drag and drop ui javascript simple drag and drop page builder js build javascipt project with drag and drop tools draggable javascript Drag and drop connectors using javascript js draggable
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source