You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sergio edited this page Oct 24, 2020
·
4 revisions
schema of the basic .addEventListener, fetch(), catch() and callback:
addEventListener to all elements
when the event is triggered a Callback is fired
the Callback will fetch() something from the db.json
then() we modify the DOM using event.target to identify which element the event was triggered from
constEMPTY_HEART='♡'constFULL_HEART='♥'letheartStates={"♡": "♥","♥": "♡"};letarticleHearts=document.querySelectorAll(".like");functionlikeCallback(e){letheart=e.target;fetch("/bogus_url").then(function(){heart.innerText=heartStates[heart.innerText];}).catch(function(error){console.log('there was an error)
});}for(letheartofarticleHearts){heart.addEventListener("click",likeCallback);}