您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页jQuery中insertAfter()方法用法实例

jQuery中insertAfter()方法用法实例

来源:纷纭教育


这篇文章主要介绍了jQuery中insertAfter()方法用法,实例分析了insertAfter()方法的功能、定义及匹配的元素插入到另一个指定的元素集合后面的使用技巧,需要的朋友可以参考下

本文实例讲述了jQuery中insertAfter()方法用法。分享给大家供大家参考。具体分析如下:

此方法把匹配的元素插入到另一个指定的元素集合的后面。
insertAfter()方法与insertBefore()方法的作用相反。

语法结构:

代码如下:

$(selector).insertAfter(content)

参数列表:

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

实例代码:

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<title>insertAfter()
函数
-脚本之家</title> 
<style type="text/css"> 
p{ 
 width:100px; 
 height:100px; 
 border:1px solid red; 
} 
p{ 
 width:200px; 
 height:200px; 
 border:1px solid blue; 
} 
</style> 
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script> 
<script type="text/javascript"> 
$(
document
).ready(function(){ 
 $("button").click(function(){ 
 $("p").insertAfter("p"); 
 }) 
}); 
</script> 
</head> 
<body> 
<p>我的前面会被插入内容</p> 
<p>我是p元素</p> 
<button>点击查看效果</button> 
</body> 
</html>

以上代码可以将p元素插入到p元素的下面,当然是外部的下面。

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务