<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>");

 

相关文章:

  • 2021-11-07
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2021-08-24
  • 2021-11-30
猜你喜欢
  • 2021-04-14
  • 2022-12-23
  • 2021-07-10
  • 2022-02-21
  • 2021-05-18
  • 2022-12-23
相关资源
相似解决方案