Skip to content

Instantly share code, notes, and snippets.

@adhadse
Last active November 27, 2020 13:58
Show Gist options
  • Save adhadse/0a3194c4dc2f1725ed0207a61869aa4e to your computer and use it in GitHub Desktop.
Save adhadse/0a3194c4dc2f1725ed0207a61869aa4e to your computer and use it in GitHub Desktop.
using javascript to search the element
window.addEventListener('load',function () {
console.log('Loaded')
let wislistBtns = document.querySelectorAll('.update-wishlist')
if (wislistBtns) {
for (let i = 0; i < wislistBtns.length; i++) {
wislistBtns[i].addEventListener('click', function () {
const productID = this.dataset.product
const action = this.dataset.action
console.log('productID:', productID, 'Action:', action)
if (user === 'AnonymousUser') {
console.log('User is Anonymous')
} else {
updateUserWishlist(productID, action)
}
})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment