jQuery中after的用法

简介:

 

after() 方法在被选元素后插入指定的内容。

 

法一:

在每个p元素后插入内容:

$("button").click(function(){
      $("p").after("<p>Hello world!</p>");
});

 

 

法二:

 $("button").click(function(){
    $("p").after(function(n){
            return "<p>The p element above has index " + n + "</p>";
    });

});

 

after中函数必须返回一个html字符串。

 

原帖地址:http://www.w3school.com.cn/jquery/manipulation_after.asp

  

目录
相关文章
|
1月前
|
JavaScript
jQuery :nth-of-type(n)选择器的用法详解
jQuery中,:nth-of-type(n)选择器可以对selector选择器匹配选择到的所有HTML元素进行二次匹配选择,为了更好地阐述:nth-of-type(n)的语法,这里假设selector是一个元素p选择器,如此,:nth-of-type(n)可以用于匹配p元素选择器选择到的p元素指向的父元素中第n个类型为p的子元素,而且与p是否是该父元素的第n个子元素无关,比如
43 5
|
8月前
|
JavaScript 前端开发 API
【前端用法】jQuery在线引用地址(全)
【前端用法】jQuery在线引用地址(全)
1182 0
|
6月前
|
JavaScript
jQuery学习(八)—before方法、after方法、insertBefore方法、insertAfter方法
jQuery学习(八)—before方法、after方法、insertBefore方法、insertAfter方法
|
8月前
|
缓存 前端开发 JavaScript
【前端用法】jquery获取当前页面的URL信息
【前端用法】jquery获取当前页面的URL信息
64 0
|
1月前
|
JavaScript 程序员
让我们一起抄代码,JQuery 用法整理
让我们一起抄代码,JQuery 用法整理
37 0
|
存储 JavaScript 前端开发
【前端每日一问002】jquery中each与data方法的用法与概念
【前端每日一问002】jquery中each与data方法的用法与概念
|
JavaScript
jQuery $.makeArray()方法的用法
jQuery $.makeArray()方法的用法
229 0
jQuery  $.makeArray()方法的用法
|
JavaScript 前端开发
jQuery $.inArray()方法的用法
在 jQuery 中,我们可以使用$.inArray()方法来判断某个值是否存在于数组中。
613 0
jQuery $.inArray()方法的用法
|
JavaScript
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
184 0
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
|
JavaScript
jQuery的用法
1. jQuery的引入2. jQuery的入口函数3. 小结
144 0