How to change the colour of selected button when clicked using target method?
I am a beginner and want to know how do I change the colour of the selected clicked button using the target method?
var buttons = document.querySelectorAll(".btn").length;
for (var i = 0; i < buttons; i++) {
document.querySelectorAll(".btn")[i].addEventListener("click", function () {
document.querySelectorAll(".btn").style.backgroundColor = "red";
});
}
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
<button class="btn">abc</button>
from Recent Questions - Stack Overflow https://ift.tt/3kExR1T
https://ift.tt/eA8V8J
Comments
Post a Comment