rikket
rikket

Reputation: 2407

Change DIV text with javascript

The following code changes a div's background-color when another div is dragged on it. How can I modify it it to change divs's text instead of background colour (for example I drop a div with a <p>Test</p> inside it and I want to the div which was dragged onto to change its text to <p>Test</p>

code:

$(".snap").droppable({
    drop: function (event, ui) {
        var drag = ui.draggable;
        var drop = $(this);
        $(this).html(drag.html());
        $(this).attr('name', drag.attr('id'));
        debugger;
    }
});

Please check my JSFiddle code which is not working:

JSFiddle link

Upvotes: 0

Views: 152

Answers (2)

tymeJV
tymeJV

Reputation: 104775

You can do:

$(this).html(drag.html());

In place of:

$(this).css("background-color", drag.css("background-color"));

Upvotes: 2

Derek
Derek

Reputation: 3435

Replace

$(this).css("background-color", drag.css("background-color"));

with

drop.html(drag.html());.

Upvotes: 2

Related Questions