InsertBefore methods (JavaScript and jquery)

Source: Internet
Author: User

Speaking of the InsertBefore () method, in fact JavaScript and jquery have this method, then they use the same?

In fact, there is a little difference. Anyway, I love to confuse, make a small note first!

  1. InsertBefore () method (JavaScript)

Grammar:

  node. insertbefore (newnode,existingnode)//Both of these parameters are required

  The InsertBefore () method inserts a new child node before the existing child node.

NewNode is a node object, which is the node you want to insert; Existingnode is also a node object that adds a child node before the new node.

For example:

  

  

  2. InsertBefore () method (JQuery)

Grammar:

  $ (content). InsertBefore (selector)

Note: If the method is used for an existing element, the elements are removed from the current position and then added to the selected element

For example: Insert a SPAN element before each P element

  

InsertBefore methods (JavaScript and jquery)

Related Article

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.