0

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

7
  • Why are you using 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.
    – Barmar
    2 hours ago
  • I don't understand the question. Are you asking how to show everything when the search input is empty?
    – Barmar
    2 hours ago
  • "allow user to" what? You never finished that sentence.
    – Barmar
    2 hours ago
  • So currently all results set comes and user is allow to search from there , now want to show only search bar once users start writing in search bar results start coming as per the text enter
    – Ashok
    2 hours ago
  • That still makes no sense to me. How can you show the search bar only after the user starts writing in it? If you don't show it, they won't be able to write in it.
    – Barmar
    2 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.