javascript drag and drop list

Solutions on MaxInterview for javascript drag and drop list by the best coders in the world

showing results for - "javascript drag and drop list"
Tommaso
04 Oct 2019
1// Code By Webdevtrick ( https://webdevtrick.com )
2var btn = document.querySelector('.add');
3var remove = document.querySelector('.draggable');
4 
5function dragStart(e) {
6  this.style.opacity = '0.4';
7  dragSrcEl = this;
8  e.dataTransfer.effectAllowed = 'move';
9  e.dataTransfer.setData('text/html', this.innerHTML);
10};
11 
12function dragEnter(e) {
13  this.classList.add('over');
14}
15 
16function dragLeave(e) {
17  e.stopPropagation();
18  this.classList.remove('over');
19}
20 
21function dragOver(e) {
22  e.preventDefault();
23  e.dataTransfer.dropEffect = 'move';
24  return false;
25}
26 
27function dragDrop(e) {
28  if (dragSrcEl != this) {
29    dragSrcEl.innerHTML = this.innerHTML;
30    this.innerHTML = e.dataTransfer.getData('text/html');
31  }
32  return false;
33}
34 
35function dragEnd(e) {
36  var listItens = document.querySelectorAll('.draggable');
37  [].forEach.call(listItens, function(item) {
38    item.classList.remove('over');
39  });
40  this.style.opacity = '1';
41}
42 
43function addEventsDragAndDrop(el) {
44  el.addEventListener('dragstart', dragStart, false);
45  el.addEventListener('dragenter', dragEnter, false);
46  el.addEventListener('dragover', dragOver, false);
47  el.addEventListener('dragleave', dragLeave, false);
48  el.addEventListener('drop', dragDrop, false);
49  el.addEventListener('dragend', dragEnd, false);
50}
51 
52var listItens = document.querySelectorAll('.draggable');
53[].forEach.call(listItens, function(item) {
54  addEventsDragAndDrop(item);
55});
56 
57function addNewItem() {
58  var newItem = document.querySelector('.input').value;
59  if (newItem != '') {
60    document.querySelector('.input').value = '';
61    var li = document.createElement('li');
62    var attr = document.createAttribute('draggable');
63    var ul = document.querySelector('ul');
64    li.className = 'draggable';
65    attr.value = 'true';
66    li.setAttributeNode(attr);
67    li.appendChild(document.createTextNode(newItem));
68    ul.appendChild(li);
69    addEventsDragAndDrop(li);
70  }
71}
72 
73btn.addEventListener('click', addNewItem);
74
queries leading to this page
drag drop list jsdrag and drop using jsjavascript drag and drop between listsdrag and drop in jsdrag and drop list items in javascripthtml5 drag and drop list examplejavascript div list drag and drop examplejs how to make a list items rearrange drop and dragdrag drop by jsdraggable list jsdrag and drop with html5 and jsdrag drop list javascriptjavascript drop and dragdraggable list javascriptdrag and drop codedrag and drop lists jsdrag and drop list javascriptdrag and drop list logic in javascriptjavascript drag and dropjs drag and drop divjs draggable listdrag and drop in htm and get codedrag adn drop lists jsjavascript draggable listdrage and drop list using jsjavascript drag drop between 2 listdrag and drop a text valuedrag and drop todo list javascriptdrag and drop sortable list javascriptjs drag drop libdrag and drop on elementjs drag and drop dropendcss drag and drop componentsjs drag and droparray elements drag and drop in jshtml draggingdrag and drop list ordering javascriptjavascript drag and drop libhow to add drag optiondrag and drop 2bjsjs drag image and drop on imagejavascript drag and drop sortable listhtml 5 draggablejavascript create a drag and drop listvaniila js drag drop listdrag and drop to do list javascriptjavascript drag and drop functiondrag adn drop jsjavascript drag and drop list exampledrag and drop using javascripthow to make a draggable list jsdragon drop htmleasy js drag and drop listdrag drop javascript examplejavascript swipe drag list itemsjavascript drag and drop listdrag drop item jsjavascript drag and dropddrag and drop in javascriptjavascript drag and drop every wherehtml drag and drop listdraggable tutorialhow to make a draggable list javascriptjs drag and drop listhtml drag and drop list itemson drop function in javascriptdrag and drop list jssort list drag drop jsdraggble html exempledrag and drop js examplejavascript swipe list item with dragjavascript drag and drop order listjavascfipt drag and drop listdrag and drop drop jsdroppable htmljs drag and drop list targetdrag and drop with jsjavascript dragable listjavascript drag and drop exampledrag and drop implementation in jsjavascript drag and drop sortablejs how to drag and drop thingsjs drag dropdrag and drop elements in jsdrag and drop with javascriptdrop on drop off html cssdrag and drop sort list javascriptdrag drop html5js drag and drop list mdnjs ul draggable and dropdrag and drop javascriptdrag and drop list with javascriptvanilla js drag and drop listjs list with draggable itemsjavascritp drag and dropdrag and drop list items javascriptjs drop and dragdrag drop image jsdraggable list items javascriptli drag and drop javascriptdrag 26 drop with javascriptdrag and drop html css javascriptlist drag and drop javascripthow to drag and drop javascriptdrag and dropt javascriptdrag and drop array javascriptmdb drag and drop menu javasciprtjavascript drag and drop list orderhow to drag and drop using javascriptdrag and drop li elements javascriptjavascript drag examplesimple drag and dropdrag to dropable jsdrag and drop example jsjavascript drag dropvanilla javascript drag and drop listhtml drag and drop list exampledrag and drop list in jsjavascript drag and drop reorder listjavascript drag and drop list