How to move an element into another element?

前端 未结 15 2275
無奈伤痛
無奈伤痛 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:19

    If you want a quick demo and more details about how you move elements, try this link:

    http://html-tuts.com/move-div-in-another-div-with-jquery


    Here is a short example:

    To move ABOVE an element:

    $('.whatToMove').insertBefore('.whereToMove');
    

    To move AFTER an element:

    $('.whatToMove').insertAfter('.whereToMove');
    

    To move inside an element, ABOVE ALL elements inside that container:

    $('.whatToMove').prependTo('.whereToMove');
    

    To move inside an element, AFTER ALL elements inside that container:

    $('.whatToMove').appendTo('.whereToMove');
    

提交回复
热议问题