Reputation: 13
Examples:
list tag created dynamically:
var newli = document.createElement('li');
newli.id = "fstId";
How do you give this list tag the property " ondragstart="drag(event)" "?
please advise me...
Thank you.
Upvotes: 1
Views: 1062
Reputation: 626
Drag & Drop are event that are passed down to any DOM elements. While creating a element dynamically you first have to enable its draggable property & add event for drag & other events flowed by in Drag & Drop you can find it in details below
Further you can add those event & flag like this given below,
var node = document.createElement("li");
node.draggable = true;
node.addEventListener('drag', setDragging);
Here setDraging is a callback function on which you have to describe what to do when dragging. You can find the complete implementation below here but its better to go first to previous link I described above. Here is the full implementation,
Upvotes: 1