jQuery如何从<div>中删除所有<span>标签?

Lag*_*una 13 jquery dom-manipulation

我尝试了以下两种方法,但没有一种方法可行:

$('#divhtml').remove('span')

$('#divhtml').find('span').remove()
Run Code Online (Sandbox Code Playgroud)

编辑: $('#divhtml').find('span').remove()第二次尝试.

And*_*rpi 29

您已经使用了正确的声明:

$('#divhtml').find('span').remove()
Run Code Online (Sandbox Code Playgroud)

这应该工作.请提供更多上下文...请将此jsfiddle视为"证明"其他错误:http://jsfiddle.net/Pbgqy/


小智 8

试试这个:

$("#divhtml span").remove()
Run Code Online (Sandbox Code Playgroud)

  • 这与`$('#divhtml').find('span').remove()`相同,只是使用`find()`函数更快(不需要字符串操作). (4认同)