Home >Web Front-end >JS Tutorial >Usage examples of insertBefore() method in jQuery_jquery

Usage examples of insertBefore() method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:21:331092browse

The example in this article describes the usage of insertBefore() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method inserts the matching element in front of another specified element collection.
The insertBefore() method is the opposite of insertAfter().

Grammar structure:

Copy code The code is as follows:
$(selector).insertBefore(content)

Parameter list:
参数 描述
selector 定义要被插入的内容。
content 定义在哪些元素之前插入内容。

实例代码:

复制代码 代码如下:






insertBefore()函数-脚本之家
 
 
 
 
 

 
 

 

以上代码可以将div元素插入到p元素的前面。
需要特别注意的是,这里的插入是将匹配元素挪动到指定元素的前面,而不是复制一个新的。

希望本文所述对大家的jQuery程序设计有所帮助。

Statement:
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