jQuery duplicate DIV into another DIV

后端 未结 5 765
北海茫月
北海茫月 2020-11-29 00:46

Need some jquery help copying a DIV into another DIV and hoping that this is possible. I have the following HTML:

  
5条回答
  •  孤街浪徒
    2020-11-29 01:42

    You'll want to use the clone() method in order to get a deep copy of the element:

    $(function(){
      var $button = $('.button').clone();
      $('.package').html($button);
    });
    

    Full demo: http://jsfiddle.net/3rXjx/

    From the jQuery docs:

    The .clone() method performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes. When used in conjunction with one of the insertion methods, .clone() is a convenient way to duplicate elements on a page.

提交回复
热议问题