如何使用 id 删除 javascript 中的 Div 元素?

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

How to remove Div elements in javascript using their id?

javascriptdom

提问by NOVICE TANUJ

Possible Duplicate:
JavaScript: remove element by id

可能的重复:
JavaScript:按 id 删除元素

I only know their respective ids and don't know specifically about their parent nodes....

我只知道他们各自的 id,并不特别了解他们的父节点......

回答by Florian Margaine

You can use parentNodeon the element to get its parent, and use removeChildon it.

您可以parentNode在元素上使用以获取其父级,并removeChild在其上使用。

var el = document.getElementById( 'id' );
el.parentNode.removeChild( el );

回答by xdazz

In jQuery, just $('#your_id').remove();will work.

在 jQuery 中,就$('#your_id').remove();可以了。