按ID删除元素 - Remove element by id

问题:

This question was migrated from Server Fault because it can be answered on Stack Overflow. 此问题是从“服务器故障”迁移而来的,由于能够在“堆栈溢出”中回答。 Migrated 9 years ago . 迁移 9年前 Learn more . 了解更多

When removing an element with standard JavaScript, you must go to its parent first: 使用标准JavaScript删除元素时,必须首先转到其父元素: node

var element = document.getElementById("element-id");
element.parentNode.removeChild(element);

Having to go to the parent node first seems a bit odd to me, is there a reason JavaScript works like this? 首先必须去父节点对我来讲有点奇怪,JavaScript是否有这样的缘由? 服务器


解决方案:

参考一: https://stackoom.com/question/EDDv/按ID删除元素
参考二: https://oldbug.net/q/EDDv/Remove-element-by-id
相关文章
相关标签/搜索