当前位置: 动力学知识库 > 问答 > 编程问答 >

Adding items to the top of the list with JavaScript

问题描述:

This question already has an answer here:

  • How to set DOM element as the first child?

    5 answers

网友答案:
list.insertBefore(entry, list.firstChild);

See https://developer.mozilla.org/en-US/docs/Web/API/Node.insertBefore

网友答案:

.appendChild() will add the element to the last, if you want to prepend any element, you can use .insertBefore()

Incase jQuery, then .prepend()

分享给朋友:
您可能感兴趣的文章:
随机阅读: