0

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

2
  • I know its not in the spirit of SO but sometimes I just want to scream : en.wikipedia.org/wiki/RTFM Commented May 23, 2013 at 16:41
  • 1
    Aside: Since you cached $(this) as drop, you should replace both instances of $(this) with drop. Commented May 23, 2013 at 16:44

2 Answers 2

2

Replace

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

with

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, can you please check my updated included JSFiddle link. tks
2

You can do:

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

In place of:

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

1 Comment

Thanks for your answer, can you please check my updated included JSFiddle link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.