简体   繁体   中英

How to move an element in the DOM?

I have an element #superWidget in the DOM that is very interactive. It uses jquery UI sortable, draggable, and a bunch of other plugins.

<div id="wrapperA"></div>
<div id="wrapperB">
  <div id="superWidget"></div>
</div>

I want to change the position of #superWidget in the DOM. I want to remove it from #wrapperB and place it in #wrapperA.

<div id="wrapperA">
  <div id="superWidget"></div>
</div>
<div id="wrapperB"></div>

I have tried the following...

var copy = $("#superWidget").clone(true, true);
$("#superWidget").remove();
$("#wrapperA").append(copy);

...however this breaks a lot of the plugins.

I do not want to have to rebind everything. Is there a better way to do this? (I notice that jquery UI sortable is somehow able to move elements around in the DOM without breaking any interactivity... there must be a way.)

Thanks (in advance) for your help

而不是重复,只需这样做:

document.getElementById('wrapperA').appendChild(document.getElementById('superWidget'));

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