我有一个div,我想在其中添加另一个div.但是,通过使用appendChild()它总是在容器元素的末尾插入DOM元素.但我想将它插入容器的开头div.
怎么做到这一点?
var newDiv= document.createElement('div');
newDiv.innerHTML = "<input type='text'/>";
var item = document.getElementById('containerDivId');
item.appendChild(newDiv);`
Run Code Online (Sandbox Code Playgroud)