I am a bit stuck and hoping someone can help me, please.
Basically I have coded a shopping cart and am currently trying to get the cart to display a message saying "Cart is empty" after all of the cart items have been removed.
Everything is working ok apart from the "Cart is empty" message being re-displayed after the cart is empty.
I have tried a few things but cannot seem to get the emptyCartMessage to display when removing the last cart item.
Just for extra context my cart items each have an independent ‘remove’ button attached to them.
My code is below.
Thank you for any help, I do appreciate it!
const currentCartItems = document.getElementsByClassName('cart-item');
const emptyCartMessage = document.createElement('p');
emptyCartMessage.innerHTML = 'Your cart is empty.';
// EMPTY CART ITEM DISPLAY MESSAGE
shoppingCart.appendChild(emptyCartMessage);
// SHOPPING AREA BUTTON EVENT LISTENER
for (var i = 0; i < addToCartButton.length; i++) {
addToCartButton[i].addEventListener('click', createCartItem);
}
function createCartItem(event) {
//CREATE CART LI ITEM
const newItem = document.createElement('li');
newItem.className = 'cart-item';
//newItem.innerHTML = event.target.value;
//GET AND SET SHOP/CART ITEM VALUE
const itemValue = document.createElement('p');
itemValue.innerHTML = event.target.value;
//CREATE CART ITEM DESCRIPTION
const p = document.createElement('p');
p.innerHTML = itemDescription;
//CREATE CANCEL CART ITEM BUTTON
const cancelItemImage = document.createElement('img');
cancelItemImage.className = "remove-button";
cancelItemImage.src = "images/cancel-icon.png";
cancelItemImage.alt = "red remove icon";
newItem.appendChild(itemValue);
newItem.appendChild(p);
newItem.appendChild(cancelItemImage);
shoppingCart.appendChild(newItem);
if (currentCartItems.length > 0) {
emptyCartMessage.className = 'hide-empty-cart';
} else if (currentCartItems.length <= 0) {
emptyCartMessage.classList.remove('hide-empty-cart');
}
}
buy cytotec amazon
provigil for adhd – provilgil.com modafinil and birth control
buy prednisolone 40 mg
accutane price – accutane without a prescription accutane cost in india
viagra dosage recommendations
where can i buy prednisolone tablets for dogs in the uk
advair price in canada
ivermectin medicine – ivermectin pills human ivermectin 200
buy cialis online with paypal – tadalafil prescription canada order cialis online without prescription
ivermectin for covid – ivermectin 6 tablet
sildenafil 100mg price
buy viagra online
lyrica buy online uk – fastphapl canadian compounding pharmacy
amoxil 500mg – amoxilin amoxicillin over counter
ivermectin cream cost – ivermectin coronavirus ivermectin 6mg dosage
prednisone 10 mg – order prednisone buy prednisone online canada
provigil 100mg – provigil provigil online
tadalafil 20 mg
vardenafil hcl
buy generic zithromax 250mg – zithromaxr buy azithromycin online
This blog was… how do you say it? Relevant!! Finally I’ve
found something which helped me. Many thanks! http://antiibioticsland.com/Cipro.htm
amoxil mg
cross border pharmacy canada – discount canadian cialis online pharmacy nz cialis
Hiya very cool site!! Man .. Beautiful .. Superb .. I will bookmark your web site and
take the feeds also? I am glad to search out a lot of useful
info right here within the submit, we need develop more techniques in this regard, thanks for sharing.
. . . . . http://droga5.net/
cheap ventolin inhalers
buy oral ivermectin – purchase stromectol online ivermectin 0.1 uk
amoxicillin for wounds
casino real money – free slots slot machines
amoxicillin for chest infection
ed pills walmart – ed medication low cost ed pills
how can i get prednisone – prednisone capsules over the counter prednisone medicine
Hello! Someone in my Myspace group shared this site with us so I came
to check it out. I’m definitely loving the information. I’m bookmarking and will
be tweeting this to my followers! Excellent blog and outstanding
design and style. http://herreramedical.org/azithromycin
buy viagra now – viagra tablet online purchase 100mg viagra canada
tadalafil
where to buy cialis online in australia – Buy cialis in usa viagra vs cialis
Hello, just wanted to say, I enjoyed this article.
It was helpful. Keep on posting! http://herreramedical.org/viagra
ivermectin 4 mg – stromectol for human ivermectin 6
kamagra pills
ed drugs – pharmacy medications erectile dysfunction medications
how long does sildenafil last
best canadian mail order pharmacies
lisinopril prescribed for anxiety
dapoxetine pharmacokinetics
levitra with dapoxetine
ventolin purchase – ventolin cost uk ventolin tablet price
cytotec suppository – how to get cytotec usa cytotec pills buy
can you buy doxycycline over the counter in nz – drug doxycycline cheap doxycycline
neurontin 500 mg – 300 mg neurontin levothyroxine 0.5 mg
viagra citrate 200mg – cheapest generic viagra australia
It’s appropriate time to make some plans for the future and it is time to be happy.
I’ve read this post and if I could I wish to suggest you
few interesting things or suggestions. Maybe you can write next
articles referring to this article. I wish to read even more things about it!
generic for cialis – canadian pharmacy without prescription cialis 40 mg canada
Hello there! Would you mind if I share your blog with my twitter group?
There’s a lot of folks that I think would really enjoy your
content. Please let me know. Many thanks
buy viagra canada pharmacy
generic vardenafil vardenafil – best price vardenafil generic vardenafil going generic
Sweet blog! I found it while browsing on Yahoo News. Do
you have any tips on how to get listed in Yahoo News?
I’ve been trying for a while but I never seem to get there!
Appreciate it
Greetings! Very helpful advice within this article!
It is the little changes that produce the biggest changes.
Many thanks for sharing!
Great article.
prednisone online canada – buy prednisone from canada 5mg prednisone daily
Hi there! Do you use Twitter? I’d like to follow you if
that would be okay. I’m absolutely enjoying your blog and look forward
to new posts.
50mg accutane – cost of accutane canada accutane from canada
I am really enjoying the theme/design of your blog. Do you ever run into any browser compatibility problems?
A small number of my blog visitors have complained about my blog not operating correctly in Explorer
but looks great in Firefox. Do you have any solutions to help fix this issue?
generic amoxil – antibiotics without a doctor‘s prescription where to buy amoxicillin
Fantastic goods from you, man. I have understand
your stuff previous to and you are just too magnificent.
I actually like what you have acquired here, certainly like what you are
saying and the way in which you say it. You make it enjoyable
and you still take care of to keep it smart. I can’t wait to
read far more from you. This is really a great website.
amoxicillin 500mg near me
methylprednisolone 16 mg generic – medrol 8mg price lyrica capsules price
thesis writer – essay cheap write thesis
buy stromectol 3mg – stromectol for humans ivermectin medication
Spot on with this write-up, I actually feel
this amazing site needs a lot more attention. I’ll probably be returning to read through more, thanks for the info!
cheap flights http://1704milesapart.tumblr.com/ cheap flights
Keep on writing, great job! scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery
Its like you read my thoughts! You seem to know a lot about this, such as
you wrote the book in it or something. I feel that you simply can do with a
few % to pressure the message house a bit, however other than that,
that is magnificent blog. A fantastic read.
I’ll definitely be back. ps4 https://bitly.com/3nkdKIi ps4
order deltasone – prednisone 200 mg price where can i buy prednisone over the counter
It’s a pity you don’t have a donate button! I’d certainly donate to this brilliant blog!
I guess for now i’ll settle for bookmarking and adding
your RSS feed to my Google account. I look forward to brand new updates
and will talk about this blog with my Facebook group.
Talk soon! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars
online pharmacy canada
lasix pills
ventolin generic – topventoli ventolin nebules
where to buy prednisolone eye drops
cytotec medicine – cytotec buy cytotec for sale
mail order prescription drugs from canada
doxycycline canada brand name – can i buy doxycycline over the counter prednisolone 5 mg tablet rx
advair
ivermectin oral solution – stromectol drug stromectol 3 mg dosage
how to take clomid 50mg
stromectol without prescription – ivermectin 2mg online ivermectin 8 mg
generic sildenafil india – sildenafil alternative sildenafil online
best place to buy tadalafil online reviews – buy tadalafil online canadian online pharmacy tadalafil
buy accutane 40mg online – buy accutane online where can i get accutane uk
academicwriting – pay for essays edit my paper
ivermectin 1mg – stromectol brand name ivermectin 3mg tablets
buy vardenafil 20mg online – vipps canadian pharmacy ed pills cvs
how to take vardenafil – online canadian pharmacy vitality ed pills
can i buy ivermectin online – ivermectin buy australia ivermectin brand name
Hello, this weekend is pleasant designed for me, as this moment i am reading this great educational paragraph
here at my home. http://harmonyhomesltd.com/Ivermectinum-tablets.html
prednisone dosage – prednisone no rx prednisone 500 mg tablet
ultram canadian pharmacy
pharmacy technician target store cvs
ivermectin buy – cost ivermectin buy stromectol usa
can i buy female viagra over the counter – sildenafil for ed where can you purchase female viagra
sildenafil otc usa – viagra 100mg england sildenafil canada prescription
cialis daily pill – cialis discount where can i order cialis online
ivermectin 2mg online – stromectol pills ivermectin gel
online casinos – wind creek casino online play real money online casinos usa
Everything composed was very logical. But, think about this,
suppose you added a little information? I mean, I don’t
want to tell you how to run your website, but suppose
you added a title to maybe grab people’s attention? I mean How to show "cart is empty" after all items have
been removed using Javascript? – JavaScript Help
is a little vanilla. You might peek at Yahoo’s front page and note how they
create news titles to grab viewers to open the links. You might try
adding a video or a picture or two to grab people excited about what
you’ve got to say. In my opinion, it might make your website a little bit more interesting. http://herreramedical.org/vidalista