I had a problem while testing drag and drop functions. I need the images to be dragged into the text box, and when they were deleted, the text would be added using the Twitter username, which is stored in the html user attribute “data-twname”.
The problem arises when I type the text inside the text box - any subsequent drag and drop and just does not add the twitter name to the text, even if it works at the beginning. This is the jQuery code I'm using:
$(".draggie").draggable({
containment: "parent",
cursor: "move",
revert: true,
revertDuration: 100
});
var targetName;
$(".draggie").mousedown(function(){
targetName = $(this).attr("data-twimage");
});
$("#textCompose").droppable({
accept: ".draggie",
drop: function(event) {
$("#textCompose").append(targetName);
}
});
I made a demo here to clarify: remove the demo link
source
share