Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
How to hide a div if searched text not exist

I am able to filter out data, now I am trying to hide a div if searched text doesn't exist. Is there any way to do it.

<input type="text" placeholder="Search" class=".bar-input">
    <div class="xyz"> hide me if searched value doesn't match</div>
    <ul class=".myUL">
      <li>one</li>
      <li>two</li>
      <li>three</li>
      <li>four</li>
      <li>five</li>
      <li>six</li>
    </ul>
    
    $('.bar-input').on('keyup', function() {
      var input_val = $('.bar-input').val();
      var tags = $('.myUL > li');
      var count = tags.length;
      for (i = 0; i < count; i++) {
          if (!input_val || tags[i].textContent.toLowerCase().indexOf(input_val) > -1) {
              tags[i].style['display'] = 'block';
             
          } else {
              tags[i].style['display'] = 'none';
          }
      }
    }); 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here, accept if this work for you.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<input type="text" placeholder="Search" class="bar-input">

<div class="xyz"> hide me if searched value doesn't match</div>
    <ul class="myUL">
      <li>one</li>
      <li>two</li>
      <li>three</li>
      <li>four</li>
      <li>five</li>
      <li>six</li>
    </ul>
    
    <script>
    
    $('.bar-input').on('keyup', function() {
      var input_val = $('.bar-input').val();
      var tags = $('.myUL > li');
      var count = tags.length;
      var match_cnt = 0;
      for (i = 0; i < count; i++) {
          if (!input_val || tags[i].textContent.toLowerCase().indexOf(input_val) > -1) {
              tags[i].style['display'] = 'block';
              
              match_cnt++;
             
          } else {
              tags[i].style['display'] = 'none';
          }
      }
      if(match_cnt<1) {
        $('.xyz').hide();
      } else {
        $('.xyz').show();
      }
    }); 
    
    </script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!