Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Article preview with JS

@TrakaMeitene

Desktop design screenshot for the Article preview component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Script tag is in HTML, have no idea if it is the best practice, but it's so small, I figured that it don't matter. But I con not make the button another color on mobile. It pissed me off :D This project was a little challenge for me.

Fell free to give some feedback how I could do it better.

Community feedback

@MishaHernandez

Posted

Hello TrakaMeitene 👋

  1. Adding javascript in the html is not a good practice, but if the script is very small then there is no problem and rather it turns out to be more efficient.

  2. To change the button you just need to add to the script a constant that gets the button's id and then inside the condition where the button must change color add the styles. For example:

var x = document.getElementById ("pop");
const btnShare = document.getElementById ("btnShare")
   if (x.style.display === "none") {
     x.style.display = "block";
     btnShare.style.backgroundColor = "hsl(217, 19%, 35%)";
     btnShare.color = "white";
   } else {
     x.style.display = "none";
     btnShare.style.backgroundColor = "hsl(210, 46%, 95%)";
     btnShare.color = "";
   } 

As additional observations:

  • To initialize a variable use const or let instead of var.
  • To add styles from javascript I recommend using classList which gives you more options. [HTML DOM classList Property] (https://www.w3schools.com/jsref/prop_element_classlist.asp)

I hope I can help you with these recommendations. Happy Coding ✌

1

@TrakaMeitene

Posted

@MishaHernandez <code> function myFunction() { const x = document.getElementById("pop"); if (x.style.display ="block") { x.classList.add("pop-content"); } }</code>

I took off the <code> pop-content </code> class and made this script to test it's function. Made it a lot easier to understand.

Thank You!

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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