I have a list of buttons, each of these when clicked should console log the results of a different function.
<button>Log baseData</button>
<button>Log baseData in reverse</button>
<button>Log baseData without first item</button>
<button>Log each baseData entry as a new log</button>
I have tried a forEach loop, but can't figure out how to select each of these and fire different functions without adding an onClick attribute to the selected element. Any ideas? Thanks
let btns = document.querySelectorAll('button');
btns.forEach((i)=>{
i.addEventListener('click', ()=>{
console.log(baseData, i);
});
});
btns[0].addEventListener(...); btns[1].addEventListener(...);and so on?