I've made the following fiddle where the words from one list can be dragged and dropped to the other and vice versa.
The code for drag and drop is fairly straightforward.
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("Text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
and each word has draggable="true"
while both divs have ondrop="drop(event)" ondragover="allowDrop(event)"
Now, I need a function to shuffle the words in each list.
Basically, on clicking a button, it should call a function that will shuffle the words present in either list. Honestly, i have NO idea on how to do that. I was thinking of using Javascript's
var input = a.getElementsByTagName('span')
where, in my Fiddle, the <span>
contains each separate word.
At the same time, I'm wondering if it is similar to this question. If it is, can someone help me on how to use it for my current problem.
Thanks.