document.querySelector
returns a single element which matches the selector. If you want to get all matching elements, you need to call
document.querySelectorAll
and iterate over the list.
window.onload = () => {
setTimeout(() => document.querySelectorAll('.transition.is-active').forEach(el => el.classList.remove('is-active')), 500);
document.querySelectorAll('a.transition').forEach(anchor => anchor.addEventListener('click', e => {
e.preventDefault();
e.target.classList.add('is-active');
const target = e.target.href;
setTimeout(() => window.location.href = target, 500);
}));
};
Document.querySelector() - Web APIs | MDN[
^]
Document.querySelectorAll() - Web APIs | MDN[
^]