document.addEventListener('click', e => {
const slide = e.target.closest('.slide');
if (slide) {
const index = Array.prototype.indexOf.call(
slide.parentNode.children,
slide
);
console.log(index);
}
});
или
for (const n of document.querySelectorAll('.slide')) {
n.addEventListener('click', onClick);
}
function onClick() {
let index = 0;
for (let el = this; el = el.previousElementSibling; index++) ;
console.log(index);
}
или
document.querySelectorAll('.slider').forEach(function({ children }) {
[].forEach.call(children, (n, i) => {
n.dataset.index = i;
n.addEventListener('click', this);
});
}, e => console.log(+e.currentTarget.dataset.index));