ARTICLE AD BOX
So for my present JavaScript when the user clicks the button to enter the desired squares they want to make it works but when I click it again to enter another number it doesn’t work till I reload my browser
How do I make it that when I enter an input I can still enter another input later without having to reload
That’s why I am asking if it’s possible to loop the click event and will it work for this situation.
I will appreciate any advice please
const container = document.getElementById("container");
const input = document.getElementById("btn");
const inputNew = document.getElementById("input");
function makeDivs(numDivs) {
for (let d = 0; d < numDivs; d++) {
let cells = document.createElement("div");
container.appendChild(cells)
}
}
makeDivs(256);
input.addEventListener("click", () => {
let inputReceived = prompt("Number of squares you need");
const element = document.getElementById("container");
element.remove();
userInput(inputReceived);
});
function userInput(numInput) {
for (let i = 0; i < numInput; i++) {
let cells = document.createElement("div");
inputNew.appendChild(cells)
element = document.getElementById("input");
element.classList.add("new");
}
}
<button id="btn">Input Number</button>
</div>
<div id="container"></div>
