Product cart notification using flexbox and javascript
Design comparison
Solution retrospective
I have made that when you press the "add to cart" button, a notification comes out and that when you press the button in the corner with the cart, it tells you the product that you added. How can I make the corner button only have to be pressed once and not twice?. Any advice to improve is welcome :)
Community feedback
- @Daniel77aprPosted about 2 years ago
Hey, Miguel!
I,ve had this problem before. Try using
b.style.visibility!='visible'
instead ofb.style.visibility=='hidden'
as the condition in your last function like this:cart.addEventListener('click', function hola(){ b.style.visibility!='visible'? b.style.visibility='visible': b.style.visibility='hidden'; });
I'm not sure why (beginner here), but I have noticed that JavaScript does not recognize property values previously added in CSS, only the ones added in JavaScript. So basically, after loading the page with the previous code,
b.style.visibility=='hidden'
returnsfalse
, and when you click for the first time,b.style.visibility='hidden'
is run. Now that JavaScript added thehidden
value,b.style.visibility=='hidden'
returnstrue
when clicking a second time andb.style.visibility='visible'
is run. The new code solves this sinceb.style.visibility!='visible'
returnstrue
after loading the page.Hope this helps!
0 - @VCaramesPosted about 2 years ago
Hey there! 👋 Here are some suggestions to help improve your code:
-
The Alt Tag Description for the image needs to be improved upon. You want to describe what the image is; they need to be readable. Assume you’re describing the image to someone.
-
The old price 🏷 is not being announced properly to screen readers. You want to wrap it in a Del Element and include a sr-only text explaining that this is the old price.
-
Implement a Mobile First approach 📱 > 🖥
With mobile devices being the predominant way that people view websites/content. It is more crucial than ever to ensure that your website/content looks presentable on all mobile devices. To achieve this, you start building your website/content for smaller screen first and then adjust your content for larger screens.
If you have any questions or need further clarification, let me know.
Happy Coding! 👻🎃
0 -
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord