I need the
event.target.innerHTML = FULL_HEART
event.target.setAttribute('class', 'like-glyph activated-heart')
after the displayError()
setTimeout interval is completed in the scenario that the mimicServerCall()
catches an error.
document.addEventListener('DOMContentLoaded', () => {
const likeButtons = document.querySelectorAll('.like-glyph');
const modal = document.getElementById('modal');
function displayError() {
modal.removeAttribute('class');
setTimeout(function(){ modal.setAttribute('class','hidden') }, 3000);
};
function likifyMe(button) {
button.addEventListener('click', (event) => {
if (event.target.innerHTML === EMPTY_HEART) {
mimicServerCall().then(() => {}).catch(() => {displayError()});
event.target.innerHTML = FULL_HEART
event.target.setAttribute('class', 'like-glyph activated-heart')
} else {
event.target.innerHTML = EMPTY_HEART
event.target.setAttribute('class', 'like-glyph')
}
});
};
likeButtons.forEach(button => {
likifyMe(button)
});
});
Is there a way to achieve this?