Created
May 16, 2018 10:37
-
-
Save 9jaswag/2f7e8546ac7ab5b315b6c1e324a7e813 to your computer and use it in GitHub Desktop.
drag and drop js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dragStart = (event) => { | |
event.dataTransfer.setData("text/plain", event.target.id); | |
} | |
const allowDrop = (event) => { | |
event.preventDefault(); | |
event.currentTarget.style.background = '#7f8082'; | |
} | |
const drop = (event) => { | |
event.preventDefault(); | |
const data = event.dataTransfer.getData("text/plain"); | |
const element = document.querySelector(`#${data}`); | |
event.currentTarget.style.background = 'white' | |
try { | |
event.target.appendChild(element); | |
} catch (error) { | |
console.warn("you can't move the item to the same place") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment