I am trying to dynamically add 4 buttons with different text on each of them using JavaScript. Basically when the person clicks on the initial button, another 4 buttons would pop up.
The text that shows up in each button is coming from an array, the problem is that when I click the button only one button is created with the text from the final string in the array.
What am I doing wrong?
Here's the code I am using:
var btn = document.getElementById("btn");
var option = document.createElement("button");
var optionText = ["Button 1", "Button 2", "Button 3", "Button 4"];
btn.addEventListener("click", function(){
buttonSelect();
})
function buttonSelect() {
for(var i = 0; i < optionText.length; i++){
document.body.appendChild(option);
option.innerHTML = optionText[i];
}
}