Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

I would like to move one DIV element inside another. For example, I want to move this (including all children):

<div id="source">

...

</div>

into this:

<div id="destination">

...

</div>

so that I have this:

<div id="destination">

  <div id="source">

    ...

  </div>

</div>

1 Answer

0 votes
by (40.7k points)

If you want to use the appendTo function (which adds to the end of the element), try this:

$("#source").appendTo("#destination");

Otherwise, you can use the prependTo function (which adds to the beginning of the element) like this:

$("#source").prependTo("#destination");

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...