jquery insertbefore (), InsertAfter (), after (), before () Introduction to the difference _jquery

Source: Internet
Author: User

InsertBefore (): A.insertbefore (b)

A in front, b in the back,

A: is a selector, B: is also a selector

<! DOCTYPE html>
 
 

Get:

P2:wenwen
P1:hello

InsertAfter (): With InsertBefore () is the same reason

A.insertafter (b)

A in the back, B in the front

Now it's said before ()

Before (): A.before ()

A is an existing selector on the page, B is what you need to add, note: What is what, will identify the label, B is not a selector

A in the back, B in the front

<! DOCTYPE html>
 
 

Finally get:

P1:hello
. p1

Do you see that? P1 does not recognize the selector, it is a string directly before the. P2 Selector

After (): With before () is the same, just one in the previous

I just want to say InsertBefore (), InsertAfter () and before (), after () the difference, I feel the biggest difference is to see the scene you want to use, if you need two of the selector position to swap

InsertBefore (), InsertAfter ()

If you need a selector with a text exchange position can be used before (), after (); Of course, it's not just a replacement.

The replacement position is that there is already something on the page, this method can also add to the page does not have things, such as:

$ (' <p class= ' p3 ' > Hehe </p> '). InsertBefore ('. P1 ');

The above mentioned is small set to introduce the jquery in the InsertBefore (), InsertAfter (), after (), before () difference introduction, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.