When you do a project, you need the DOM node to move, as in the following code:
The code is as follows |
Copy Code |
<div></div> <p></p> |
You need to move the P tag to the DIV tag, and after testing, it's convenient to move the DOM node in jquery:
The code is as follows |
Copy Code |
$ (' div '). Append ($ (' P ')) |
So you can move the P tag to the DIV tag, and don't write this:
The code is as follows |
Copy Code |
$ (' div '). Append ($ (' P '). HTML ()) |
This simply copies the contents of the P tag into the div tag.
If you just copy one to the div tag, the original label remains, so you can write:
The code is as follows |
Copy Code |
$ (' div '). Append ($ (' P '). Clone (True)) |
Cases
The code is as follows |
Copy Code |
$ (function () { $ (". Nm_ul li"). Click (function () { $ (this). Clone (True). Appendto (". Nm_ul"); Copy the currently clicked node and append it to the <ul> element }) }); |
Also, when the clone parameter is set to True, you can copy the event bound by the button to the new button
A parameter true is passed in the Clone () method, meaning that the event that is bound in the element is replicated while copying the element. Therefore, copies of this element also have replication capabilities. If you do not want the event to be replicated, you can write this:
The code is as follows |
Copy Code |
$ (' div '). Append ($ (' P '). Clone ()) |
Moving nodes
Moving one node on a page to another can be jq the internal and external insertion method (Append,appendto,prepend,prependto,after,before,insertafter,insertbefore), You can move the selected node directly by passing it in
code is as follows |
copy code |
<button >move me!</button> <div id= "box" ></DIV> Instance $ ("button"). Click (function () { $ (This). Appendto ($ ("#box")); //or append $ ("#box"). Append (this); }; |