fromSitePoint Forums | Web Development & Design Community
2 months agoHow to Get Reference to Original Clicked Element When Using Event Delegation
const prods = document.querySelectorAll(".products"); prods.AddEventlistener("clicked",(e)=> fetch('some url').then(res => { if (!res.ok) { throw new Error("Cannot fetch resource!") } return res.json() }) .then(data => { const arrayObject = JSON.parse(data.data); arrayObject.forEach(prod => { const markup = `<li>${prod.Info}></li>`; document.querySelector('dialog ul').insertAdjacentHTML('beforeend', markup); }); }).catch(error => console.log(error)); });
jQuery