js empty() vs remove()

Posted RainDream

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js empty() vs remove()相关的知识,希望对你有一定的参考价值。

转自:jQuery empty() vs remove()

 

  • empty() will remove all the contents of the selection.
  • remove() will remove the selection and its contents.
<div>
    <p><strong>foo</strong></p>
</div>

$(‘p‘).empty();  // --> "<div><p></p></div>"

// whereas,
$(‘p‘).remove(); // --> "<div></div>"

 

以上是关于js empty() vs remove()的主要内容,如果未能解决你的问题,请参考以下文章