开发者

Javascript Alternative to appendChild

开发者 https://www.devze.com 2023-03-11 22:32 出处:网络
I want to insert a node as a child node (element node ) at 开发者_运维知识库a fixed position(0) i.e. it should replace a child node (if there is one) and not append..

I want to insert a node as a child node (element node ) at 开发者_运维知识库a fixed position(0) i.e. it should replace a child node (if there is one) and not append..

Which function should I use to ensure crossbrowser compatiblity?


Test to see if the element has a firstChild. If it has one, use replaceChild otherwise use appendChild


Select the child and use .replaceWith()

0

精彩评论

暂无评论...
验证码 换一张
取 消