Hi @ravip413131,
Using innerHTML
to append html elements (e.g. el.innerHTML += "<a href='...'>link</a>"
) will result in the removal of any previously set event listeners. That is, after you append any HTML element that way you won’t be able to listen to the previously set event listeners.
Therefore I have added the below code please have a look :
window.onload = function () {
let num = document.getElementById("num");
let list = document.getElementById("list");
let print = document.getElementById("print");
print.onclick = function () {
let N = parseInt(num.value);
for (let i = 1; i <= N; i++) {
list.innerHTML = "<li>" + i + "</li>";
}
};
};
For more precise information refer the provided Link.