How can I clear/hide elements when a button is clicked, then make something else appear?
DracoMagnus (0)

How do I do this successfully?

You are viewing a single comment. View All
DracoMagnus (0)

W3Schools says,

HTML

JavaScript

Would the "myDIV" be the div the button is inside? I understand the variable x, but how can I do this with 3 buttons, and when you click 1, it hides all three and makes a randomly chosen string(aka the question) appear with the four answer choices(or a text input, whichever is easier)?

Bookie0 (6559)

@DracoMagnus You could make several buttons and each button has an onclick with that function, and an id that will make it hide. Then for a randomly chosen string, you can use JS to randomly pick a string out of an array.

DracoMagnus (0)

Yes, I know about arrays, but what is that code I need to write, @Bookie0 ? Also, I have 3 buttons and each one needs to hide all three but they are all in separate divs.

Bookie0 (6559)

hmm okay well try first with just one button and one div (so use the code from W3 schools). Then, you could try to add the 2 other buttons, and each button, when they're clicked, will call the JS function.

@DracoMagnus