1

タイトルで。

HTML:

<div class="active"></div>
<div></div>
<div></div>

Javascript (バニラ):

// source HTML collection, only get the elements index which has the class "active"
let theCollection = document.querySelectorAll('div'); 

// related HTML collection
let anotherCollection = document.querySelectorAll('div .anotherClass');
// adding the class the corresponding element
theCollection[index].classList.add('active');

私が取得する必要があるのは、現在active内にクラスがある要素のインデックスですtheCollection

4

2 に答える 2