I have 3 buttons. When I click one buttons in array of element, others will be disabled. How can i log unmatch buttons. Please help! thank you
JavaScript
x
9
1
btnItem.addEventListener("click", () => {
2
btnList.forEach((activeCurrent) => {
3
if (btnItem.id === activeCurrent.id) {
4
//Have Three Button Select active clicked console.log(show others)
5
}
6
});
7
});
8
});
9
Advertisement
Answer
JavaScript
1
14
14
1
(function() {
2
const buttonList = document.querySelectorAll('button')
3
4
const onClickButton = (e) => {
5
buttonList.forEach(button => {
6
if (button !== e.currentTarget) {
7
console.log(button)
8
}
9
})
10
}
11
12
buttonList.forEach(button => button.addEventListener('click', onClickButton))
13
}
14
)();
JavaScript
1
3
1
<button>btn1</button>
2
<button>btn2</button>
3
<button>btn3</button>