I have below tab in html which show search bar with results and allow user to search from there ,if user enter text it start search from that particular word now want to show only search bar once user start search it show results
<div class="tab-pane" id="tab3">
<div class="panel-group" id="help-accordion-2">
<div class="panel panel-default panel-help">
<a href="#help-three" data-toggle="collapse" data-parent="#help-accordion-2">
<div class="panel-heading panel-textHeading">
<input id="myInput" type="text" placeholder="Search..">
</div>
</a>
<div id="help-three" class="collapse in">
<div class="panel-body" id="divResults">
</div>
</div>
</div>
</div>
</div>
code for live search
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#divResults div").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
I want my div results only display results once user start search not before so currently its show all results and allow user to search from there
filter()
? That should be used when you want to return a subset of the elements that match a condition, but you're not using the result. Use.each()
if you just want to loop over the elements.