greenbandit
greenbandit

Reputation: 2275

get src from draggable img

i have this little code to drag & drop images:

$("img").draggable({
    revert: true,
    opacity: 0.7,
    cursor: "move",
    cursorAt: {
        cursor: "crosshair",
        top: -5,
        left: -5
    }
});

$('#mybox').droppable({
    drop: function () {
        $(this).append('<div style="float:left;"><img src="http://dummyimage.com/42x40/000/fff.jpg"></div>');
    }
});

the idea is: when I drag a image, instead of show the dummy image, show the image itself, but how i can get the src from image from draggable. Any Idea?

Thanks in advance.

Upvotes: 0

Views: 1520

Answers (1)

silex
silex

Reputation: 4320

Try this code:

***
$('#mybox').droppable({
    drop: function (event, ui ) {
        $(this).append('<div style="float:left;"><img src="'+ ui.draggable.attr('src') +'"></div>');
    }
});
***

Upvotes: 3

Related Questions