Can we Directly remove Nodes from a NodeList?

后端 未结 3 583
无人及你
无人及你 2020-12-31 01:01

document.getElementsByTagName returned me a NodeList object.

I would like to remove some items (let\'s say I would like to remove the first item from th

3条回答
  •  轮回少年
    2020-12-31 01:49

    Just have the same use case as you.

    For ES6 you can do this:

    const myNodeList = ele.childNodes;
    
    const [head, ...tail] = myNodeList;
    
    console.log('the first item: ', head);
    
    console.log('the remaining items: ', tail);
    

    JavaScript ES6— The Spread Syntax (…)

提交回复
热议问题