and uncomment these lines so that the buttons actually have their event listeners…
document.getElementById("emptycart").addEventListener("click", emptyCart);
var btns = document.getElementsByClassName('addtocart');
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener('click', function() {addToCart(this);});
}
The Add to Cart functions work. The total shows $, but thats because you’ve left $'s in your HTML on line 53 and in your Javascript on line 98:
I loggedin about 45 mins ago to post that I fixed it. I found the other JS $.
I then read your reply and chnaged the other HTL one.
All was working fine!
I thought I had to comment out the listeners because they were a problem. They were until about 5 minutes ago (I decided to take my shoes for a walk!).
I’ve just reread your reply. The comments aren’t meant tot be there!
Just because I quite enjoy these exercises I have updated your javascript a bit. I’m not sure where you sourced the original, but it seems quite dated.
I did this;
I’ve displayed the products as a grid on my site.
As to not mess things up, I decided on the make a few adjustments as shown below.
I’m assuming that your code selects the productname and price for the cart.
I’ve put the productname as .productname {display: none} as if would ruin my page if it was displayed.
<div class="product">
<div><p>Studio</p></div>
<div class="productName">
<h3>Energy Performance Certificate (EPC) for a Studio Apartment</h3>
<div><p>65.00</p></div>
<div class="price" style="color: blue"><p><b>55.00</b></p></div>
<div><a href="https://www.ecobunny.co.uk"><button type="button" class="addtocart">Book Now</button></a></div>
</div>
</div>
If I am right;
When product is selected that this will be shown in the cart (can you let me know?);
Energy Performance Certificate (EPC) for a studio apartment £55.00