jQuery insert insertAfter() and insertBefore()

Same as internal insertion processing, jQuery has added two new methods insertAfter and insertBefore due to different locations of content targets

before() and .insertBefore() to achieve the same function. The main difference is syntax - content and placement of goals. For before(), the selection expression is in front of the function, and the content is used as a parameter, while .insertBefore() is just the opposite, the content is in front of the method, and it will be placed in front of the element in the parameter

after() and .insertAfter () achieves the same function. The main difference is the syntax - specifically the placement of (inserted) content and targets. For after(), the selection expression is in front of the function, and the parameter is the content to be inserted. For .insertAfter(), On the contrary, if the content is in front of the method, it will be placed after the elements in the parameters

before, after and insertBefore. In addition to the difference in target and position, insertAfter does not support multi-parameter processing

Notes:

insertAfter inserts the JQuery-encapsulated element behind the specified element. If there are element, then move the following element back, and then insert the JQuery object;

insertBefore inserts the JQuery-encapsulated element in front of the specified element. If there is an element in front of the element, then move the previous element in front of it. Move, and then insert the JQuery object;

Let’s write a piece of code:

       

php 中文网

php.cn

Let’s test it and see what difference there is

Continuing Learning
||

php 中文网

php.cn

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!