1、remove([expr])
 
概述:从DOM中删除所有匹配的元素。
这个方法不会把匹配的元素从jQuery对象中删除,因而可以在将来再使用这些匹配的元素。但除了这个元素本身得以保留之外,其他的比如绑定的事件,附
 
加的数据等都会被移除。
 
<div class="pt-main">
<p class="first">第一项</p>
<ul >
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
</ul>
</div>
 
 $('p').remove();//或者  $('p').remove('.first');
 
 
2、detach([expr])
 
概述:从DOM中删除所有匹配的元素。
这个方法不会把匹配的元素从jQuery对象中删除,因而可以在将来再使用这些匹配的元素。与remove()不同的是,所有绑定的事件、附加的数据等都会保留
 
下来。
 
 $('p').detach();
 
比较:
 
<div >Google</div>
<div >Apple</div>
 
 $(function () {
        $("#apple").hover(function () {
            $(this).text("Google+");
        });
        //使用 remove() hover()事件也会被删除
        //apple = $("#apple").remove();
 
        //使用detach() hover()事件会保存下来
        apple = $("#apple").detach();
        $("body").append(apple);
          
    });
 

相关文章:

  • 2021-09-30
  • 2021-12-05
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-04
相关资源
相似解决方案