Tell us what’s happening:
I am confused on how I should proceed with this lab given I am hiding the natural styling of the button within the CSS stylesheet and only leaving the HTML entity. However, I want to fill that HTML entity with the color red. I am utilizing the .toggle() method to allow the addition and removal of the class “active” so that it can be toggled.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Favorite Icon Toggler</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Spices</h1>
<ul class="item-list">
<li>
Paprika <button class="favorite-icon" aria-label="Heart icon">♡</button>
</li>
<hr />
<li>
Red Pepper <button class="favorite-icon" aria-label="Heart icon">♡</button>
</li>
<hr />
<li>
Chili <button class="favorite-icon" aria-label="Heart icon">♡</button>
</li>
<hr />
</ul>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
body {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
ul {
width: 10rem;
margin: 0;
padding: 0;
list-style-type: none;
}
li {
display: flex;
justify-content: space-between;
}
hr {
border-style: solid;
}
button {
border-style: none;
background: none;
}
button:hover {
cursor: pointer;
}
.favorite-icon.active {
fill: red;
}
/* file: script.js */
const btns = document.querySelectorAll("favorite-icon");
btns.forEach((btn) => btn.addEventListener("click", () => {
btn.classList.toggle("active");
}));
Currently, nothing happens.
Challenge Information:
Build a Favorite Icon Toggler - Build a Favorite Icon Toggler