I want to allow drag and drop in an html unordered list. The solution I've found is described here: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop2
But it seems I need to give an id to each element of my list (li), is it possible to do a drag and drop without using the id?
Also in this solution it seems that I can drag a li inside another one, how can I prevent this?
Here's a sample of what I have now (the javascript):
function drag(ev) {
ev.dataTransfer.setData("Text",ev.target.id);
}
function allowDrop(ev) {
ev.preventDefault();
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
[EDIT] Here is the html ul:
<ul id="members-list" ondragover="allowDrop(event)"
ondrop="drop(event)">
<li id="drag1" class="group-member"
ondragstart="drag(event)"
draggable="true">
<a href="">
<img class="member-photo"
src="images/a.jpg"
alt="Bernardo Figueiredo"/>
<div class="member-info">
<p>bla</p>
<p>blabla</p>
</div>
</a>
</li>
<!-- Other li -->
</ul>