I have a list of items and a search field that filters this list as something is typed in this box. I also have a reset
button that clears the search box and focuses on it, but does not clean the filtered results based on what was typed.
Q: I am referring to this page: link
Here is the code I'm using:
$(function() {
$("#myInput").keyup(function() {
$("#body-post p").css("display", "none");
var texto = $(this).val().toUpperCase();
$("#body-post li").css("display", "block");
$("#body-post li").each(function() {
if ($(this).text().toUpperCase().indexOf(texto) < 0)
$(this).css("display", "none");
});
});
});
#myInput {
background: url('http://w3schools.com/css/searchicon.png') 10px 6px no-repeat #fff;
width: 50%;
font-size: 13px;
font-family: Open Sans;
color: #000;
padding: 8px 40px;
border: 1px solid #bbb;
transition: all 0.3s;
margin: 6px 0;
margin-left: 6px
}
#myInput:hover,
#myInput:focus {
box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.08)
}
#myInput:focus {
border: 1px solid #D80000
}
#rst {
height: 36px;
color: #2d2d2d;
border: none;
background: transparent;
}
#rst:hover {
color: #D80000
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><form><inputid='myInput'placeholder='Pesquisartexto...'title='Digitealgo...'type='text'><inputid='rst'value='×'type='reset'onclick="document.getElementById('myInput').focus();">
</form>
<div id='body-post'>
<ul>
<li><a href="http://einconformado.blogspot.com/2018/03/tristeza-e-revolta.html">207 Quando a tristeza e a revolta resolvem marcar um encontro dentro de mim</a></li>
<li><a href="http://einconformado.blogspot.com/2018/03/sete-ensinamentos-de-numeros-11.html">206 Sete Ensinamentos de Números 11</a></li>
<li><a href="http://einconformado.blogspot.com/2018/03/tenha-e-mantenha.html">205 Tenha e Mantenha</a></li>
</ul>
</div>
Thank you in advance! =]