How to move an element into another element?

前端 未结 15 2267
無奈伤痛
無奈伤痛 2020-11-22 03:35

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

...
15条回答
  •  花落未央
    2020-11-22 04:28

    If the div where you want to put your element has content inside, and you want the element to show after the main content:

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

    If the div where you want to put your element has content inside, and you want to show the element before the main content:

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

    If the div where you want to put your element is empty, or you want to replace it entirely:

    $("#element").html('
    ...
    ');

    If you want to duplicate an element before any of the above:

    $("#destination").append($("#source").clone());
    // etc.
    

提交回复
热议问题