I got multiple buttons and after a particular function is run, I wanted the div element to be set disabled until the page is reloaded. I tried making the button disable too but that didn’t work either
<div class='container'>
<div class = 'btn' id = 'rock'>
<button ><img src="./images/rock-svgrepo-com.svg"></button>
</div>
<div class = 'btn' id = 'paper'>
<button > <img src="./images/paper-plane-svgrepo-com.svg"></button>
</div>
<div class= 'btn' id = 'scissors'>
<button> <img src="./images/scissors-svgrepo-com.svg"></button>
</div>
</div>
I have used the specific javascript to disable the div
function endGame(){
const buttons = document.querySelectorAll('.btn')
buttons.disabled = true;
console.log(buttons);
};
2
Answers
Using removeEventListener fixed by terminating the function from running, Thank you though!
Return types matter.
const buttons = document.querySelectorAll('.btn')
returns a NodeList ofdiv
elements, and not a single button.So instead, you have to iterate over the list and disable each button.
As in