Created
May 9, 2020 18:42
-
-
Save alissoncs/05dbec848272be6b98084900efca5b12 to your computer and use it in GitHub Desktop.
addAwardToCart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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