Click here to Skip to main content
15,868,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm coding a website and for some reason whenever I click one button all the other buttons disappear. How do I fix this?

(I'm new to programming, so don't come after me).

What I have tried:

I don't even know how to describe what I've tried. Moving stuff around, adding a button type.


var myArrTwo = ["First item","Second item"];

document.getElementById("btn1").addEventListener("click", myDate1);
function myDate1(){
document.write(myArrTwo[0])
}

document.getElementById("btn2").addEventListener("click", myDate2);
function myDate2(){
document.write(myArrTwo[1])
}
Posted
Updated 5-Aug-20 23:11pm
v2
Comments
Garth J Lancaster 6-Aug-20 0:04am    
"(I'm new to programming, so don't come after me)." .. ok, we were all new to programming once. What I will say, is that you should probably use Improve question to provide some code detail of what you've got - preferably the smallest amount of code that illustrates the issue - otherwise it may be too hard to give you specific help.

1 solution

Making a call to document.write()[^] effectively replaces the content of the whole page, which explains why you would be seeing your buttons disappear.

Instead you might want to use something like document.getElementById()[^] and changing the HTML content of the element.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900