var wrapper = document.getElementsByClassName('.wrapper');
for(var i =0; i < 10; i++){ //create grid of buttons
var num = document.createElement("div");
var node = document.createTextNode(i);
num.appendChild(node);
wrapper.appendChild(num);
num.className = "number";
}
It throws an error that wrapper is not defined, it only worked when I used document.body instead of wrapper, but I want to append them divs to the wrapper div any suggestions ?
var wrapper = document.getElementsByClassName('wrapper');
instead of
var wrapper = document.getElementsByClassName('.wrapper');
EDIT:
var addButtons = function() {
var wrapper = document.getElementsByClassName("wrapper")[0];
var num, node;
for (var i = 0; i < 10; i++) {
console.info("Button"+i);
num = document.createElement("div");
num.className = "number";
node = document.createTextNode(i);
num.appendChild(node);
wrapper.appendChild(num);
}
}
addButtons();
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.