首页 > 其他 > 详细

after() 和 remove() 实现替换

时间:2016-02-22 15:33:44      阅读:184      评论:0      收藏:0      [点我收藏+]

<div class="replacedDiv">this is the replaced div</div>

<script>
            $(function(){
                $("div.replacedDiv").after("<p>i will replace the div</p>").remove();
            });
</script>

结果是新建的p替换了原来的div。

 

note: 总是可以将有用的语句封装起来形成jquer拓展

$.fn.replaceWith = function(html){

  return this.after(html).remove();

}

利用这个拓展,执行上面的效果可以用这个语句:

$("div.replaceDiv").replaceWith("<p>i will replace the div</p>");

 

after() 和 remove() 实现替换

原文:http://www.cnblogs.com/rocky-fang/p/5206869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!