I want to append a newly created div into the next to last position of an element but I am a beginner and I'm not quite sure how to select that position.
var div = document.createElement("div");
div.className = "test";
div.innerHTML = "some stuff";
document.getElementById('content').appendChild(div);
Something like
var div = document.createElement("div");
div.className = "test";
div.innerHTML = "some stuff";
var parent = document.getElementById('content');
var children = parent.children;
parent.insertBefore(div, children[children.length-1]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.