首页 > 技术文章 > js empty() vs remove()

drizzlewithwind 2017-08-20 14:46 原文

转自: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>"

 

推荐阅读