jQuery DOM

create node

var box = $('<div id="box">node</div>'); Create a node
$('body').append(box); //Insert the node inside the <body> element

insert node

append(content) inserts a node after the specified element content
append(function(index,html){}) uses an anonymous function to insert a node after the specified element
appendTo(content) moves the specified element inside the specified element content
prepend(content ) Insert a node to the front of the specified element content
prepend(function(index,html){}) Use an anonymous function to insert a node to the front of the specified element
prependTo(content) Move the specified element to the front of the specified element content

External Insert Node Method

after(content) inserts the node after the outside of the specified element
content after(function(index,html){}) uses an anonymous function to insert the node after the outside of the specified element
before(content) inserts the node before the outside of the specified element content
before( function(index,html){}) Use an anonymous function to insert a node before the outside of the specified element
insertAfter(content) Move the specified node to the back of the content of the specified element
insertBefore(content) Move the specified node to the front of the outside of the specified element content

wrap node

wrap(html) wraps a layer of html code
to the specified element wrap(element) wraps a layer of DOM object node to the specified element
wrap(function(index){}) uses an anonymous function to wrap a layer of custom content to the specified element
unwrap() move wraps
all elements together in html
wrapAll(element) wraps all elements together in a DOM object
wrapInner(html) wraps a layer of html to the child content of the specified element
wrapInner(element ) Wrap a layer of DOM object node to the child content of the specified element
wrapInner(function(index){}) Use an anonymous function to wrap a layer to the child content of the specified element


Node operation
$('body').append($('div').clone(true)); Copy a node and add it to HTML
$('div').remove(); Directly delete the div element
$('div ').detach(); keep the event behavior delete
$('div').empty(); delete the content of the node

$('div').replaceWith('<span>node</span>'); replace div with span element
$('<span>node</span>').replaceAll('div'); same as above

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325008790&siteId=291194637