What is the procedure to reduce my final search result by 1?

When the search is triggered, I want to filter the images by name. However, the issue arises when trying to make everything disappear on filter addition.

<ul id="list2"> 
          <li class="in2">

An extra number is added to the result in some cases - for example, if there are 8 images, it shows 9. When searching for something with 2 results, it displays 3 instead. How can I subtract 1 from the search result?

Here's my code:

<ul id="list2">
      <div class="chartGap">  
          <li class="in2">
                <button class="customAccordion chartBackGroundColor">
                      <p class="chartTitle">Limestone</p>
                      <p class="chartViewAll">View All
                       <span class="list-count2"></span>
                            <svg class="chartIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                  class="bi bi-arrow-down-short" viewBox="0 0 16 16">
                                  <path
                                        d="M8 4a.5.5 0 0 1 .5.5v5.793l2.146-2.147a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 1 1 .708-.708L7.5 10.293V4.5A.5.5 0 0 1 8 4z" />
                            </svg>
                      </p>
                </button>
                <div class="panel">




<main class="chartMain">
      <div class="chartContainer">


    <li class="in2"> <div class="card">
        <div class="card-image">
            <a loading="eager"
                href="https://cdn.shopify.com/s/files/1/0098/8318/9314/files/OMNIAR_BEIGE_-_ROULLATO_-_LIMESTONE_result.jpg?v=1669391209"
                data-fancybox="gallery-omniar-beige-roullato-limestone" data-caption="OMNIAR BEIGE ROULLATO LIMESTONE">
                <img
                    src="https://cdn.shopify.com/s/files/1/0098/8318/9314/files/OMNIAR_BEIGE_-_ROULLATO_-_LIMESTONE_result.jpg?v=1669391209"
                    alt="OMNIAR BEIGE ROULLATO LIMESTONE">
            </a>
        </div>
        <h1 class="galleryCustomH">OMNIAR BEIGE <br> ROULLATO <br> LIMESTONE</h1>
    </div> </li>
    
    
    
    <li class="in2"> <div class="card">
        <div class="card-image">
            <a loading="eager"
                href="https://cdn.shopify.com/s/files/1/0098/8318/9314/files/OMNIAR_BEIGE_-_HONED_-_LIMESTONE_result.jpg?v=1669391209"
                data-fancybox="gallery-omniar-beige-honed-limestone" data-caption="OMNIAR BEIGE HONED LIMESTONE">
                <img
                    src="https://cdn.shopify.com/s/files/1/0098/8318/9314/files/OMNIAR_BEIGE_-_HONED_-_LIMESTONE_result.jpg?v=1669391209"
                    alt="OMNIAR BEIGE HONED LIMESTONE">
            </a>
        </div>
        <h1 class="galleryCustomH">OMNIAR BEIGE <br> HONED <br> LIMESTONE</h1>
    </div> </li>

    ...

      </div>
    </main>


                </div>
                </div>
          </li>
    </ul>





<script>
      $(document).ready(function() {
      
        var jobCount = $('#list2 .in2').length;
        $('.list-count2').text(jobCount + ' items');
          
        
        $("#search-text").keyup(function () {
           //$(this).addClass('hidden');
        
          var searchTerm = $("#search-text").val();
          var listItem = $('#list2').children('li');
        
          
          var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
          
            //extends :contains to be case insensitive
        $.extend($.expr[':'], {
        'containsi': function(elem, i, match, array)
        {
          return (elem.textContent || elem.innerText || '').toLowerCase()
          .indexOf((match[3] || "").toLowerCase()) >= 0;
        }
      });
          
          
          $("#list2 li").not(":containsi('" + searchSplit + "')").each(function(e)   {
            $(this).addClass('hiding out').removeClass('in2');
            setTimeout(function() {
                $('.out').addClass('hidden');
              }, 300);
          });
          
          $("#list2 li:containsi('" + searchSplit + "')").each(function(e) {
            $(this).removeClass('hidden out').addClass('in2');
            setTimeout(function() {
                $('.in2').removeClass('hiding');
              }, 1);
          });
          
        
            var jobCount = $('#list2 .in2').length;
          $('.list-count2').text(jobCount + ' items');
          
          //shows empty state text when no jobs found
          if(jobCount == '0') {
            $('#list2').addClass('empty');
          }
          else {
            $('#list2').removeClass('empty');
          }
          
        });
      });
      
      </script>

Answer №1

Below is a proposed fix

let numberOfWorkers = $('.employees .in2').length - 1;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What modifications need to be made to the MEAN app before it can be deployed on the server?

Following a tutorial on Coursetro, I was able to successfully build an Angular 4 MEAN stack application. However, when it comes to deploying the app on a server running on Debian-based OS, I am facing some challenges. The application should be accessible o ...

What are some effective strategies for preventing CSS duplication?

What is the best way to prevent repeating CSS code like this: div#logo div:nth-child(1) div { width: 30%; height: 30%; background-color: white; } div#logo div:nth-child(3) div { width: 30%; height: 30%; background-color: white; ...

What is the best way to enable an image to be moved on top of another image?

Is there a way to allow users to drag around an image that is positioned on top of another image in an HTML file? I want the superimposed image to stay within the boundaries of the underlying image. Any suggestions on how this can be achieved? <html& ...

ajaxToolkid: TabContainer feature allows for displaying a box when tabs are clicked

Currently, I have implemented ajaxToolkid TabContainer along with TabPanels and everything seems to be functioning correctly. However, upon clicking on the tabs, a box is being displayed. The image below shows what is currently being displayed: tabs displ ...

Ensuring that links are functional across all directory levels: a comprehensive guide

Looking at the image included here, you can see a preview of the website I'm currently building. The plan is to have individual pages for each machine in the company's lineup. Since the navigation bar and menu will be consistent across the entire ...

jQuery Mobile and Phonegap: Content Disappears from Page Header After Transition Finish

My phonegap (2.2.0) + jquery mobile (1.2.0) app is experiencing a peculiar problem. There is a page in my app with a link that loads another page. On the loaded page, there is a back button that takes the user back to the previous page when clicked. This ...

Dynamic JavaScript Line Graph

I am facing a challenge with a small function in my application that needs to display real-time data on a webpage. I have been exploring different Javascript examples, such as the Flot example "real-time updates" and the Highcharts example "spline updating ...

Troubleshooting issue: `will_paginate` and jQuery integration not functioning properly due to non-responsive

I'm currently implementing a pagination feature in my application using jQuery, similar to how it's done on platforms like Facebook and Twitter. However, when I try to load "next" results, the entire HTML page is being loaded instead. It seems li ...

Utilizing Bootstrap datepicker to set maximum and minimum dates based on another date input

I have been attempting to create a restriction on the date selection, where datepicker1 cannot exceed datepicker2, and vice versa. Initially, I tried implementing this feature using (Linked Pickers). Unfortunately, this did not achieve the desired date in ...

Role-based dynamic layout

I am currently working on a website that requires user login functionality. To achieve this, I am utilizing materialise-css and Angularjs for the front-end development, while the back-end is powered by Java-Hibernate (as Spring is not an option in my case) ...

What could be causing the background image on my Jumbotron to fail to load?

Having some trouble with setting my image as the background of the Jumbotron. I've tried a few different approaches, but none seem to be working. It's not an issue with static loading because using img src directly into the Jumbotron section does ...

Error code TS7053 occurs when an element implicitly has an 'any' type because a string expression cannot be used to index an empty object

I have implemented a code snippet that sorts items into groups based on their first character. For example, if the array of item looks like this: {name: 'Foo'} {name: 'Bar'} {name: 'Baz'} The expected result should be: B: ...

Is the input box failing to show up on your screen?

I recently tackled the task of creating a commenting feature for RSS articles Throughout my journey with PHP coding, I encountered an issue where the input box for comments was not displaying. https://i.stack.imgur.com/gJIlu.png Check out the snippet fr ...

Dynamic WordPress Website Designs

Seeking recommendations for responsive WordPress themes that offer extensive CSS and structural customization options. The goal is to retain all of WordPress's built-in features, such as blogging capabilities, while having the freedom to completely co ...

What is the size limit for JSON requests in Node.js?

I am seeking information about the req object in nodeJS. Let's say I have a code that sends data in JSON format to my server using an AJAX POST method. Now, imagine a scenario where a user manipulates my client code to send an excessively large JSON f ...

Displaying Multiple HighCharts on a single AngularJS page

As a beginner with HighCharts, I am working on adding two Highcharts to the same page that will access the same data source but display different pieces of data for each graph. For example, the categories will remain constant while the series[] will vary. ...

javascript Incorrectly using location.reload will not refresh the page as intended

My goal is to refresh a page every time a user clicks a button so the page reverts back to its original source code. However, I am facing an issue where the location.reload() function is being executed after the code instead of at the beginning. btn.addEve ...

Issue encountered while attempting to install the node-jasper package

I'm encountering an error stating that python.exe is not found, despite having installed Python and added it to the environmental variables. I've also attempted using Node versions 8, 10, and 12 without success. I tried installing node-jasper fo ...

Displaying Angular JS data in the Laravel application using the URL::route facade

I'm currently working on an Angular JS + Laravel Application. On one of the pages, I have a list of users that I fetch, and when a row is clicked, it redirects to the edit user page. Below is a snippet of my code: Blade Template <tbody> &l ...

Is there a way to direct back to the AJAX error function from the application_error in the

Why does my code keep ending up in the AJAX success function instead of the error function? What mistake am I making? $.ajax({ url: url, type: "POST", data: data, contentType: "application/json; charset=utf-8", success: function(data) ...