jQuery 在 div 中查找 div 并将其删除?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12595633/
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-26 11:50:44  来源:igfitidea点击:

Find div inside a div and remove it?

jquery

提问by Rakesh Sawant

I want to remove div inside the div with class chartsbar Here is my html code

我想用类 chartsbar 删除 div 里面的 div 这是我的 html 代码

<div class="chartsbar" style="position: absolute; bottom: 0px; left: 27.28%; display: none; height: 0%; background-color: rgb(7, 134, 205); color: rgb(255, 255, 255); width: 0.9730252100840335%; text-align: left; " rel="0" title="09-09-2012 - 0 (0%)">

<div style="text-align:center">
0
</div>

<span style="display: block; width: 100%; position: absolute; bottom: 0; text-align: center; background-color: #0786CD;">
09-09-2012
</span>

</div>

i tried

我试过

$('.chartsbar').find('div').first().remove();

but not seems to be working.

但似乎没有工作。

回答by mbinette

$('.chartsbar div').remove(); 

It should work!

它应该工作!

Keep it simple!

把事情简单化!

EDIT

编辑

If you only want to remove the first one:

如果您只想删除第一个:

$('.chartsbar div:first').remove(); 

回答by Mark

You can achieve this with a simple selector. This will remove the first div child.

您可以使用一个简单的选择器来实现这一点。这将删除第一个 div 子项。

$(".chartsbar > div:first-child").remove();

回答by rexcfnghk

Try $('.chartsbar').children().first().remove()

尝试 $('.chartsbar').children().first().remove()

回答by Sushanth --

Try:

尝试:

$('.chartsbar > div').remove();

Or:

或者:

$('.chartsbar div').remove();

Check FIDDLE.

检查小提琴

回答by Gautam3164

Try with this

试试这个

$('.chartsbar').find('div:eq(0)').remove();

or directly use

或直接使用

$('.chartsbar div').remove();