When clicking on the search icon (🔍) the input's visibility (type="text") does not change even though it has been specified in the JS code.
var searchIcon = document.getElementById("search-icon"); // the search icon
var searchBox_input = document.getElementById("search-box");
searchIcon.addEventListener("click", function() {
if(searchBox_input.style.visibility == "hidden") {
searchBox_input.style.visibility = "visible";
} else if(searchBox_input.style.visibility == "visible") {
searchBox_input.style.visibility = "hidden";
}
});
#search-box {
position: absolute;
visibility: hidden;
top: 0px;
left: 120px;
height: 100%;
width: 130px;
border-radius: 2px;
}
#search-box:hover {
border: 2px solid darkgrey;
}
#search-icon {
position: absolute;
top: 0px;
left: 80px;
}
#search-icon:hover {
background-color: rgba(255, 255, 255, 0.8);
cursor: pointer;
}
<div id="taskbar">
<div id="start" class="btn">MyOS</div>
<div id="search">
<div id="try"><i id="search-icon">🔍</i><input type="text" placeholder="Type here to search" id="search-box"></div>
</div>
</div>
Why? How do I fix it?
visibilityit'sdisplaydisplay: noneanddisplay: block;Element.styleonly returns the inline style of the element I think, and since it doesn't have any, it's returning "".