How to append a childnode to a specific position

前端 未结 3 1831
温柔的废话
温柔的废话 2020-12-08 03:53

How can I append a childNode to a specific position in javascript?

I want to add a childNode to the 3rd position in a div. There are other nodes behind it that need

3条回答
  •  眼角桃花
    2020-12-08 04:31

    You can use .insertBefore():

    parentElement.insertBefore(newElement, parentElement.children[2]);
    

提交回复
热议问题