I have made a simple searchbar with default background color of dark. On focus it will be white. After I click the box, the color changes, but when I click outside of the box the color is still white. When I click outside of the box, the color should be dark again.
Javascript
function searchbar()
{
searchbar=document.getElementById("searchbar");
searchbar.style.background="#fff";
}
CSS
#searchbar{
background: #666;
height: 25px;
width: 345px;
}
#search{
width: 300px;
height: 25px;
float: left;
border: 0;
}
#searchicon{
width: 10px;
padding: 2px;
margin: 2px;
float: left;
cursor: pointer;
}
#searchadv{
color: #000;
width: 10px;
padding: 2px;
margin: 2px;
float: left;
cursor: pointer;
}
#search input[type="text"] {
background: #666;
height: 23px;
width: 295px;
border: 0;
}
#search input[type="text"]:focus {
background: #fff;
}
HTML
<div id="searchbar" onclick="searchbar()">
<div id="search">
<input type="text" placeholder="Search" />
</div>
<div id="searchicon">
<img src="img/search.png" />
</div>
<div id="searchadv">
<img src="img/down-arrow.png" />
</div>
</div>