How can I remove a child node in HTML using JavaScript?

前端 未结 9 1430
野的像风
野的像风 2020-12-12 20:22

Is there a function like document.getElementById(\"FirstDiv\").clear()?

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 21:08

    Modern Solution - child.remove()

    For your use case:

    document.getElementById("FirstDiv").remove()
    

    This is recommended by W3C since late 2015, and is vanilla JS. All major browsers support it.

    Mozilla Docs

    Supported Browsers - 96% May 2020

提交回复
热议问题