I have a text area (from which I take a number) and button to submit the value, and I’m trying to add content to a paragraph that is generated by this loop:
var countNum = document.getElementById(num).value;
var entNum = parseInt(countNum);
for(i=1;i<=entNum;i++){
if(i%3!==0 && i%7!==0){
document.write(i + "<br>");
}
}
now when i use document.write of course the whole previous content is overwritten, but I want to have a paragraph under the button, that receives the generated numbers from the loop and them. What’s the right way to do it ?
Lets assume you have a container below your button, where you’ll put your stuff in:
Then you can fill the container by calling
You’ll find out the rest! 😉
EDIT:
Following your comment, the following addition:
To remove an element, you’ll need a reference to it.
By ID:
By TagName:
By Reference:
More to find out:
NOW: Removing it:
You have to tell the parentContainer that it should remove a child element. Fortunately, each element saves a reference to its parent: