After () function
The after () method inserts the specified content after the selected element.
Before () function
The before () method inserts the specified content before the selected element.
Remove () function
The remove () method removes selected elements, including all text and subnodes.
This method does not delete matching elements from the jQuery object, so you can use these matching elements in the future.
Except for the element itself, remove () does not retain the jQuery data of the element. Other events such as bound events and additional data will be removed. This is different from detach.
Example: element replacement
| The code is as follows: |
Copy code |
/* * Replace A with B * After (B) inserts B to the end of A and returns the package set containing. * Remove () delete the previous package set **/ $ (A). after (B). remove (); // Simple plug-in Encapsulation $. Fn. replaceWidth (ele ){ Return this. after (ele). remove (); } |
Add two examples
1. replaceWith ()
Replace the selected content with the content in the brackets.
| The code is as follows: |
Copy code |
$ ("# Div"). replaceWith ("<div id =" div2 "> div2 </div> "); |
Use the above method to replace the element with ID div with the DIV element with ID div2.
2. replaceAll ()
Replace the selected content with the selector in the brackets.
| The code is as follows: |
Copy code |
$ ("<Div> replaced content </div>"). replaceAll ("p "); |
Use the above method to replace all p tags with the selected DIV tags.