Monday, September 18, 2023
HomeCSSjavascript - Just how to Toggle course of numerous aspects making use...

javascript – Just how to Toggle course of numerous aspects making use of querySelectAll?


I have an OnClick occasion and also each img aspect has a distinct mathematical identifier specified in “data-index”.

The objective is to transform css course of both aspects when the picture or period aspect are clicked.

Now I can just toggle the course of either the picture or the period aspect
This resembles a personality choose display.

 feature selector() {

var getSlots = Array.from( document.querySelectorAll('. slotimage', '. charname'));.
for (var i = 0; i < < getSlots.length; i++) {
getSlots[i] dataset.index = i;.
getSlots[i] onclick = feature( e) {
var index = this.dataset.index;.

if (this.classList.contains(' unselected')) {
this.classList.toggle(" unselected");.
this.classList.add(" picked");.
} else {
this.classList.toggle(" picked");.
this.classList.add(" unselected");.
}
};.
}
}

I have actually attempted making use of getSlots[i] classlist yet I maintain obtaining a mistake.
If I do not make use of "this" after that absolutely nothing jobs

I have actually obtained ~ 30 things so I require to toggle the designs of the one I clicked

RELATED ARTICLES

Most Popular

Recent Comments