0

I made a toggle function that change the parent of a child element with some code from HERE. But I want to know if there is a way to change the parent with animation, because now it just jump from one div to another.

This is the fiddle

Here is some code:

function SW()
{
    $("#SW").toggle(function(){
        var element = $("#RelativeChild").detach().appendTo("#ParentRight");
    },
    function(){
        var element = $("#RelativeChild").detach().appendTo("#ParentLeft");
    });
}
Community
  • 1
  • 1
Victor
  • 109
  • 1
  • 14

1 Answers1

0

Do it like this:

var element = $("#RelativeChild").hide('fade').detach().appendTo("#ParentRight")
.end().show('fade');

Full function:

function SW() {
    $("#SW").toggle(function () {
        var element = $("#RelativeChild").hide('fade').detach().appendTo("#ParentRight")
        .end().show('fade');
    },

    function () {
        var element = $("#RelativeChild").hide('fade').detach().appendTo("#ParentLeft")
        .end().show('fade');
    });
}

Demo

Amit Joki
  • 58,320
  • 7
  • 77
  • 95