How to move an element into another element?

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

    You can use following code to move source to destination

     jQuery("#source")
           .detach()
           .appendTo('#destination');
    

    try working codepen

    function move() {
     jQuery("#source")
       .detach()
       .appendTo('#destination');
    }
    #source{
      background-color:red;
      color: #ffffff;
      display:inline-block;
      padding:35px;
    }
    #destination{
      background-color:blue;
      color: #ffffff;
      display:inline-block;
      padding:50px;
    }
    
    
    I am source
    I am destination

提交回复
热议问题