Jquery also occasionally uses dom operations to move DOM nodes. The authors will share with you how to use jQuery to move dom nodes.
Note that moving a dom node is different from copying a dom node. Moving a dom node moves a dom node from one location to another. After moving a dom node, there is only one. The copy dom node will become two after the operation. Below are some examples to explain.
Assume that the page has the following code segment:
<Body> <div> http://www.phpernote.com/javascript-function/586.html </div> <p> jquery dom operation example </p> </body>
To move the <p> label to the <div> label, perform the following operations:
$(function(){$('div').append($('p'));});
After the operation, the html code of the page will look like the following:
<Body> <div> http://www.phpernote.com/javascript-function/586.html <p> jquery dom operation example </p> </div> </body>
The following describes the methods that js uses to operate dom nodes: append, appendTo, prepend, prependTo, after, before, insertAfter, and insertBefore.
Articles you may be interested in
- Summary of how jquery copies dom nodes
- How does jquery bind events to dynamically created nodes?
- Move the mouse over the text to display the floating layer prompt special effects (compatible with all browsers such as IE and Firefox)
- Js obtains the height of the scroll bar from the top and bottom of the browser. It is compatible with ie and firefox.
- Insert a node before the current jquery Node
- JavaScript deletes a DOM Node
- JQuery DOM node insertion method summary
- JQuery DOM node insertion method summary