首頁  >  文件處理  > remove([expr])

返回值:jQuery remove( [expr] )

概述

從DOM中刪除所有匹配的元素。

這個方法不會把匹配的元素從jQuery對像中刪除,因而可以在將來再使用這些匹配的元素。但除了這個元素本身得以保留之外,其他的比如繫結的事件,附加的資料等都會被移除。

參數

expr String V1.0

用於篩選元素的jQuery表達式

示例

描述:

從DOM中把所有段落刪除

HTML 程式碼:

<p>Hello</p> how are <p>you?</p>
jQuery 程式碼:

$("p").remove();
結果:

how are

描述:

從DOM中把帶有hello類的段落刪除

HTML 程式碼:

<p class="hello">Hello</p> how are <p>you?</p>
jQuery 程式碼:

$("p").remove(".hello");
結果:

how are <p>you?</p>