I need to know an index of a target element. My code throws an error. Does not .indexOf() work for NodeList?
const divs = document.querySelectorAll('div');
function isFirst(event) {
// Fine
console.log(event.target == divs[0]);
// But... Error! Why?
console.log(divs.indexOf(event.target));
}
divs.forEach(e => e.addEventListener('click', isFirst));
<div>0</div>
<div>1</div>
<div>2</div>
<div>3</div>