I'm trying to only show the "This is an item" text when hovering each checkbox link. For some reason, the "This is an item" text still seems to show when when checkbox link is not hovered over. Is there any way to only show text when the checkbox item is hovered over?
var accordions = document.getElementsByClassName("accordion");
for (var i = 0; i < accordions.length; i++) {
accordions[i].onclick = function() {
this.classList.toggle('is-open');
var content = this.nextElementSibling;
if (content.style.maxHeight) {
// accordion is currently open, so close it
content.style.maxHeight = null;
} else {
// accordion is currently closed, so open it
content.style.maxHeight = content.scrollHeight + "px";
}
}
}
/* Filter Display */
.filter-box {
background-color: #f5f5f5;
display: flex;
flex-direction: column;
gap: 6px;
margin-top: 10px;
}
.filter-box button {
background-color: rgb(49, 49, 49);
color: white;
}
/* Section Buttons */
button.accordion {
width: 30%;
background-color: black;
border: none;
outline: none;
text-align: left;
padding: 15px 20px;
font-size: 14px;
color: white;
cursor: pointer;
transition: background-color 0.2s linear;
color: white;
}
button.accordion:after {
font-family: "fontawesome";
font-size: 14px;
float: right;
}
button.accordion.is-open:after {
content: '\f056';
}
button.accordion:hover,
button.accordion.is-open {
background-color: grey;
}
.accordion-content {
width: 30%;
background-color: rgb(255, 255, 255);
border-left: 1px solid black;
border-right: 1px solid whitesmoke;
padding: 0 20px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-in-out;
}
.accordion-content li {
list-style-type: none;
}
.accordion-content li:hover {
font-weight: bold;
color: red;
}
.item-description {
display: none;
}
.accordion-content li:hover,
.item-description {
display: contents;
}
<button class="accordion">Catagories</button>
<div class="accordion-content">
<div class=list-item>
<li>
<label>
<input type="checkbox" name="checkbox" />Item1
</label>
</li>
<p class="item-description">This is an item</p>
</div>
<div class=list-item>
<li>
<label>
<input type="checkbox" name="checkbox" />Item2
</label>
</li>
<p class="item-description">This is an item</p>
</div>
<div class=list-item>
<li>
<label>
<input type="checkbox" name="checkbox" />Item3
</label>
</li>
<p class="item-description">This is an item</p>
</div>
</div>
text in the bottom and only initiate text when hovering beside each checkbox.
` or `
`. Browsers are unpredictable with invalid markup
tag need to wrap around the entire- tags or just the
- tags within each of the divs?
– WeeklyButterfly34 Jun 05 '21 at 19:14