简体   繁体   中英

Append Jquery Object into HTML element

I want to append $(this).parent() into another div and then remove $this element.
I am able to successfully remove $this element. But .append($(this).parent()) seems a wrong approach and not working. I want to make an exact copy into another div before removal of $this element.

Reproduced the problem statement: https://jsfiddle.net/rvgo3Luc/

Use clone() to duplicate the element and then append the cloned element.

$("#button").on("click", function(){
  console.log($(this).parent());
  // I have to copy this element into say a new div and remove this present element.
  // How to append $(this).parent()
  $("#a").append($(this).parent().clone());
  $(this).remove();
})

JSFIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM