There are many ways for jquery to insert a dom node. Here we mainly describe how to insert a node before the current node is implemented in jquery.
In jquery, the method for inserting nodes before matching nodes is before () insertBefore.
The before () method inserts the specified content before the selected element.
Syntax $ (selector). before (content)
Example:
$ ('. Insert '). click (function () {var str = '<div> insert content </div>'; $ ('# phpernote '). before (str );});
Example of inserting a node before the current node:
$ ('Click '). click (function () {var str = '<div> insert content </div>'; $ (this ). before (str );});
The insertBefore () method inserts HTML tags or existing elements before the selected elements. Note: If this method is used for existing elements, these elements are removed from the current position and added before the selected element.
Syntax $ (content). insertBefore (selector)
Example of inserting a node before the current node:
$ ('Click '). click (function () {var str = '<div> insert content </div>'; $ (str ). insertBefore (this );});
Articles you may be interested in
- JQuery DOM node insertion method summary
- JQuery DOM node insertion method summary
- Shoulder, back muscle group exercise-Bring Up-bend up rowing-Move up-Stand Up-Stand up weight bend up-Sit posture neck pull down-bend upright hold up-neck front wide hold up
- How to obtain the complete url address and parameters in javascript
- JavaScript calculates the number of characters currently entered
- MySQL inserts data when the record does not exist
- How to exercise can increase both strength and muscle
- Js address bar special effects (display the size of all images with links on the page and view the height of the current browser)