I am new to JavaScript and need some help!
I am trying to create something like a keyboard: creating a grid and then inserting Bootstrap buttons with the alphabet letters on them. I want it to be 4 rows, each with 7 columns. I tried to create only one row with multiple columns, but it doesn't work, it creates only one row with one column. How do I fix this?
HTML:
<div class="row justify-content-center container" id="buttons-space"></div>
JavaScript:
var alphabet =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
function createKeyboard() {
var space = document.getElementById("buttons-space");
var row = document.createElement("div");
row.id = "first-row";
row.className = "row container";
space.appendChild(row);
for (var i = 1; i <= 7; ++i) {
var col = document.createElement("div");
col.className = "col-1 my-2 mx-2";
document.getElementById("first-row").appendChild(col);
var button = document.createElement("button");
button.className = "btn btn-warning";
button.style = "height: 40px; width: 40px";
button.id = alphabet[i];
button.innerText = alphabet[i];
col.appendChild(button);
}
}
I must use only JavaScript, not CSS.