Insert a node before the current jquery Node

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.