Insertion, deletion, copying, and replacement of nodes
Add a brother at the end of .append ( combined with appendTo() to remember )
Add a brother to the front of .prepend ( prependTo () to remember )
.before I add a brother in front ( combined with insertBefore to remember )
.after add a brother to my back ( combined with insertAfter() to remember )
.detach() stealth
.remove suicide
.empty body is hollowed out
.clone copy ( true full copy false shallow copy, no events)
.replaceWith deletes and replaces nodes (combined with .replaceAll() to remember)
.wrap everyone plus a dad
Remove:
empty(): The node element is still there
remove(): removes the element itself
the difference:
empty method
- Strictly speaking, the empty() method is not to delete the node, but to empty the node, it can empty all descendant nodes in the element
- empty cannot delete its own node
remove method
- This node and all descendant nodes contained in this node will be deleted at the same time
- Provides an expression passed a filter to remove elements from the specified collection
Deletion of retained data:
detach();
replace:
replaceWith()、replaceAll():
- The functions of .replaceAll() and .replaceWith() are similar, the main difference is the location of the target and the source
- The .replaceWith() and .replaceAll() methods remove all data and event handlers associated with the node
- The .replaceWith() method, like most other jQuery methods, returns a jQuery object, so it can be chained with other methods
- The jQuery object returned by the .replaceWith() method refers to the node before replacement, not the node replaced by the replaceWith/replaceAll method
pack:
wrap:
$(‘p’).wrap(‘<div></div>’)
.closest(), firstly matches upwards from itself, if it matches the first one that meets the requirements, it stops matching.
.parents (), which matches from the element parent all the way up, finds all matching elements that match the requirements.
next(),prev(),siblings()