按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
相關文章
相關標籤/搜索