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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8931955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:16:25  来源:igfitidea点击:

jQuery how to remove all <span> tags from a <div>?

jquerydom-manipulation

提问by Laguna

I've tried both of the following but none of them worked:

我已经尝试了以下两种方法,但都没有奏效:

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

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

EDIT:$('#divhtml').find('span').remove()worked on 2nd try.

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

回答by Anders Arpi

You have already used a correct statement:

您已经使用了正确的语句:

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

This should work. Please provide more context... See this jsfiddle as "proof" that something else is wrong: http://jsfiddle.net/Pbgqy/

这应该有效。请提供更多上下文......将此jsfiddle视为其他错误的“证明”:http: //jsfiddle.net/Pbgqy/

回答by Troy Barlow

Try this:

尝试这个:

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