jQuery API 返回首页目录 | jQuery API 中英文对照版
remove(expr)
remove(expr)

从DOM中删除所有匹配的元素。

这个方法不会把匹配的元素从jQuery对象中删除,因而可以在将来再使用这些匹配的元素。 可以通过一个可选的表达式对要删除的元素进行筛选。

返回值:jQuery

参数:

  • expr (String): (可选)用于筛选元素的jQuery表达式
 

示例:

$("p").remove();

HTML 代码:

<p>Hello</p> how are <p>you?</p>

结果:

how are

示例:

$("p").remove(".hello");

HTML 代码:

<p class="hello">Hello</p> how are <p>you?</p>

结果:

how are <p>you?</p>

 
remove( expr )

Removes all matched elements from the DOM. This does NOT remove them from the jQuery object, allowing you to use the matched elements further.

Can be filtered with an optional expressions.

Return value: jQuery
Parameters:

  • expr (String): (optional) A jQuery expression to filter elements by.
 

Example:

 $("p").remove();  

Before:

 <p>Hello</p> how are <p>you?</p>  
Result:
 how are  

Example:

 $("p").remove(".hello");  
Before:
 <p class="hello">Hello</p> how are <p>you?</p>  
Result:
 how are <p>you?</p>  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog