Skip to content

Instantly share code, notes, and snippets.

@alissoncs
Created May 9, 2020 18:42
Show Gist options
  • Save alissoncs/05dbec848272be6b98084900efca5b12 to your computer and use it in GitHub Desktop.
Save alissoncs/05dbec848272be6b98084900efca5b12 to your computer and use it in GitHub Desktop.
addAwardToCart.js
function addAwardToCart(award) {
var div = document.createElement('div');
div.id = 'cart-item-' + award.id;
if (document.getElementById(div.id)) {
return;
}
div.appendChild(document.createTextNode('Added: ' + award.name + ', Price: $' + award.price));
var button = document.createElement('button');
button.innerHTML = 'Remove';
div.appendChild(button);
document.getElementById('cart-list').appendChild(div);
total = total + award.price;
updateTotal();
button.addEventListener('click', function (award, button, div) {
document.getElementById('award-' + award.id + '-button').innerHTML = 'Buy Tickets'
div.parentNode.removeChild(div);
total = total - award.price;
updateTotal();
}.bind(null, award, button, div));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment