Home > Web Front-end > JS Tutorial > A brief discussion on the difference between jQuery before and insertBefore

A brief discussion on the difference between jQuery before and insertBefore

高洛峰
Release: 2017-01-03 16:57:27
Original
1121 people have browsed it

In jQuery, you can use before and insertBefore to insert specified content before the specified element. There are differences in writing methods.

Let’s look at an example first:

In

Insert
toInsertContent

Implementation:

$('

toInsertContent
').insertBefore($( '.div1'));

or

$('.div1').before('

toInsertContent
');

Result :

toInsertContent

div1

Wrong writing:

$ ('

toInsertContent
').before($('.div1'));

Result:

Not only will the element not be inserted in front of div1, but it will Delete div1

Summary:

Before is the element inserted in front of, followed by the inserted content element

insertBefore is preceded by the inserted content element, followed by which element Inserting

in front of an element cannot be reversed.

The above article briefly discusses the difference between jQuery before and insertBefore. This is all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

For more articles on the difference between jQuery before and insertBefore, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template