<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<ul id="ul">
<li>旧节点</li>
</ul>
</div>
<script>
let ul = document.getElementById(‘ul‘);
let new_li = document.createElement(‘li‘);
new_li.style.backgroundColor=‘pink‘;
new_li.innerHTML=‘新节点‘;
ul.appendChild(new_li);
let new_li2 = document.createElement(‘li‘);
new_li2.style.backgroundColor=‘pink‘;
new_li2.innerHTML=‘新节点2‘;
ul.insertBefore(new_li2,ul.children[0]);
</script>
</body>
</html>
插入节点element.appendChild(要插入的节点),element.insertBefore(要插入的节点,参考节点)案例