Document processing: Including internal inserts, external inserts, replacements, deletions, replication, etc.
One: Internal insert
use |
description |
example |
|
append content to each matching element |
$ ("P"). Append ("<b>Hello</b>"); |
|
Method is reversed for general $ (A). Append (B) operation, Instead of appending B to a, append a to the B |
$ ("P"). AppendTo ("div"); |
|
forward content to each matching element |
&NB Sp $ ("P"). Prepend ("<b>Hello</b>"); |
|
reversed the operation of General $ (A). prepend (B), That is, instead of putting B in front of a, place a forward to B |
$ ("P"). Prependto ("#foo"); |
Two: External insertion
Use |
Description |
Example |
|
Insert content after each matching element |
$("p").after("<b>Hello</b>");
|
|
Insert content before each matching element |
$("p").before("<b>Hello</b>");
|
|
$ (A). After (B) operation, Which is not to insert B behind a, Instead, insert a into the back of B. |
|
|
$ (A). Before (B) operation, That is, instead of inserting b in front of a, Instead, insert a into front of B. |
|
Three: Replace
Use |
Description |
Example |
|
Replaces all matching elements with the specified HTML or DOM element |
$("p").replaceWith("<b>Paragraph. </b>");
|
|
Replace all selector matched elements with matching elements |
$("<b>Paragraph. </b>").replaceAll("p");
|
Four: Delete
Use |
Description |
Example |
|
Delete all child nodes in the matching element collection |
$("p").empty();
|
|
Remove all matching elements from the DOM |
$("p").remove();
|
V: Cloning
Use |
Description |
Example |
- Clone ([Even[,deepeven]])
|
Clones matching DOM elements and selects copies of these clones |
$("b").clone().prependTo("p");
|
jquery-Document Processing