Design comparison
SolutionDesign
Solution retrospective
What are you most proud of, and what would you do differently next time?
I discovered how to harness SVGs and use them for easier DOM.
What challenges did you encounter, and how did you overcome them?I had problems with the SVG element, but I was able to handle with the help of w3schools.
What specific areas of your project would you like help with?I'm not sure... But if there is/are more better/easier way(s) to handle the JavaScript part of the challenge, I'd be happy to know.
Community feedback
- @huyphan2210Posted about 1 month ago
Hi, @Abas-code
I checked out your solution and I have some thoughts:
- External CSS and JS files: While including CSS in your HTML isn’t wrong, the CSS in your file is getting quite lengthy. It would be better to move it into a separate file, like
style.css
, and reference it in your HTML. The same goes for your JavaScript - consider creating ascript.js
file to keep things more organized. - Inline event handling: Instead of using
share.addEventListener("click", toggle);
in your JavaScript, you could handle the click event directly in your HTML by adding anonclick
attribute to theshare
element. This simplifies the code a bit:
<div class="share" onclick="toggle()"> <!-- Your content --> </div>
- Refactoring with
classList
: You can clean up the toggle functionality by usingclassList
to manage CSS classes instead of directly modifying styles in JavaScript. This way, you keep the visual changes in your CSS, making the code more maintainable and readable:
const share = document.querySelector(".share"); const ssvg = document.querySelector(".share-svg"); const links = document.querySelector(".links"); share.addEventListener("click", toggle); function toggle() { share.classList.toggle("active"); ssvg.classList.toggle("active"); links.classList.toggle("visible"); }
Don’t forget to add the necessary classes in your CSS for this to work:
/* Initial styles */ .share { background-color: rgb(236, 242, 248); } .share-svg { fill: rgb(110, 128, 152); } .links { display: none; } /* Active styles */ .share.active { background-color: rgb(109, 127, 151); } .share-svg.active { fill: white; } .links.visible { display: flex; }
Hope this helps!
0 - External CSS and JS files: While including CSS in your HTML isn’t wrong, the CSS in your file is getting quite lengthy. It would be better to move it into a separate file, like
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