How do I write something in Javascript so one thing happens when two buttons are hit?
For example, I want something like this
<button>A</button>
<button>B</button>
<img id = "pics" src = "/randompicture.gif">
And in JS, I want to be able to make something visible when both button A and B are selected.
If(button A is hit AND button B is hit){
then this happens,
such as document.getElementById("pics").visibility = "hidden"}
Thank you
PS: Sorry for bad syntax. I'm new to HTML, CSS and JS. Any help is greatly appreciated.
Edit: By "selecting", I mean when both buttons are pressed at least once
Edit 2: Just tried @ Khauri McClain's event listeners suggestion in repl.it. It seems to have worked, I got what I wanted. Here's what I wrote
document.getElementById("buttonWithFirstId").addEventListener("click", function(){
document.getElementById("buttonWithSecondId").addEventListener("click", function(){
document.getElementById("imageId").style.visibility = "visible"
});
});
Edit 3: Wow, there's a lot of ways of doing this, it seems. I'm excited to try these. Thank you for all these different suggestions.
Thank you everyone for your suggestions.