0
Follows my code:
function yvlcs() {
var buttonsYv = [];
document.querySelectorAll('.yv-container-ul li').forEach(function (e) {
buttonsYv.push(e);
e.addEventListener('click', function (e) {
if(e.path[0].className == "") {
buttonsYv[0].removeAttribute('class');
buttonsYv[1].removeAttribute('class');
this.className = "yv-btn-active";
}
})
});
}
yvlcs()
Look at the buttonsYv[0].removeAttribute('class');
and the buttonsYv[1].removeAttribute('class');
You’d be able to put that together in one line, just to use one removeAttribute('class')
instead of two?
EDIT
I didn’t want to remove with foreach, because this way I already did, I want to know if there are any other alternatives, that look like css for example, that we can use the comma and take more than one element:
.elemento1,
.elemento2 {
display: none;
}
You will always remove only the 2 elements
index[0]
and theindex[1]
, what happens if this variable has more indices ?– RXSD