On my assignment I am only allowed to use a button, so no checkbox. Onclick of the button, certain info in shown. The code I have is working, but my question is how can I get the class to display: none, when the button is clicked again? Kind of like a toggle?
const displayScores = (e) => {
if (
(e.target.parentNode.querySelector(
".display-score-container"
).style.display = "none")
) {
e.target.parentNode.querySelector(
".display-score-container"
).style.display = "block";
e.target.innerHTML = "-";
} else {
e.target.parentNode.querySelector(
".display-score-container"
).style.display = "none";
e.target.innerHTML = "+";
}
};
return (
<div className="student-container">
<img className="student-img" src={students.pic} />
<div className="student-column">
<p className="student-item">
{" "}
{students.firstName} {students.lastName}
</p>
<p className="student-item">Email: {students.email}</p>
<p className="student-item">Company: {students.company}</p>
<p className="student-item">Skill: {students.skill}</p>
<p className="student-item">Average: {average}%</p>
<div className="display-score-container">
<p className="student-score">
Test 1:{" "}
<p className="student-percentage">{students.grades[0]}%</p>
</p>
</div>
</div>
<button
onClick={displayScores}
className="expand-btn"
>
+
</button>
)