在标题中。
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
。