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

Unlocking the JSON array of data in JavaScript: A step-by-step guide

Hey there, I need help extracting an array from a JSON data structure. Here's an example of my JSON object: { Data1 : { Data2 : "hello", Data3 : "hi" }, Data4 : { Data5 : "this is Karan", } } I'm looking ...

Uploading files with ExpressJS and AngularJS via a RESTful API

I'm a beginner when it comes to AngularJS and Node.js. My goal is to incorporate file (.pdf, .jpg, .doc) upload functionality using the REST API, AngularJS, and Express.js. Although I've looked at Use NodeJS to upload file in an API call for gu ...

Incorporating external JavaScript files into a React Element

I am currently revamping my Portfolio Site to incorporate modals into one of the pages as part of the transition to a Single Page Application (SPA). The JavaScript code for these modals is stored in a "main.js" file, and the necessary tags are included in ...

How can the click event for a SubMenu in Ant Design be deactivated?

Is there a way to keep the SubMenu from toggling its child menus when clicked, without disabling it? I would like the SubMenu to maintain its appearance while preventing its children from expanding or collapsing. ...

Troubleshooting: Why the TableTools basic usage example is not functioning as

After replicating the code from http://datatables.net/release-datatables/extensions/TableTools/examples/simple.html in my Visual Studio project, I organized the files by saving two css files as style1.css and style2.css, along with three js files named sc ...

When using the HTML a tag, it can create unexpected gaps and

I have a sentence written in PHP that I've separated into individual word components using the explode function. foreach ($words as $splitword) { echo $splitword; /* echo "<a href = 'word.php?word=" . $splitword . "'>" . $spli ...

While building with Next.js, a ReferenceError may occur if the sessionStorage is not defined

While using Next.js 13 App router, I encountered an issue with storing the JWT token received upon login in session storage. It all worked smoothly when accessing the token in my page.js pages across different routes as long as the page was a client compon ...

TypeORM ensures that sensitive information, such as passwords, is never returned from the database when retrieving a user

I developed a REST API using NestJs and TypeORM, focusing on my user entity: @Entity('User') export class User extends BaseEntity { @PrimaryGeneratedColumn() public id: number; @Column({ unique: true }) public username: string; publi ...

Implementing CSS changes during page load

My current dilemma involves using "selectors" to indicate which menu option is currently active. I have implemented two classes, selected and unselected, for this purpose. Upon page load, the selectors are correctly displayed based on the URL hash, indica ...

What is the best method for pulling in a static, plaintext JSON file into JavaScript through a GET request?

Currently, I am running a test with this specific link: accessing static json data I have encountered several issues with cross-site request errors. It is puzzling to me why it should be any different from loading an image that is hosted on the same site ...

Creating a responsive layout with Bootstrap using fluid rows and columns of varying heights

Using dynamic creation, I am tasked with generating a set of boxes each with slightly varying heights and ensuring that 2, 3, or 4 of them (based on screen size) appear on the same row. Here is an example of my attempt using Bootstrap: <div class="cont ...

Increase in JQuery .ajax timeout not effective

My website has a process where JavaScript sends a POST request to a PHP server using the .ajax() function. The PHP server then communicates with a third-party API to perform text analysis tasks. After submitting the job, the PHP server waits for a minute b ...

Warning: Node 125008 has reached the maximum number of listeners, indicating a potential memory leak in the EventEmitter

(node:125008) MaxListenersExceededWarning: There may be a memory leak with EventEmitter as 11 ready listeners have been added. Try using emitter.setMaxListeners() to raise the limit Can anyone provide guidance on how to increase the listener event count? ...

Performing a JQuery ajax request resets the values of all form fields

For years, I have been creating contact forms for my websites that include captcha verification. You can view an example here: contact form In the past, if a user wanted to reload the captcha image, the only option was to refresh the entire form. Howeve ...

Modify a specific field in a row of the table and save the updated value in a MySQL database

I have successfully retrieved data from a database and displayed it in a table. Now, my goal is to enable editing of a specific field within a row and save the updated value back into MySQL. Here is the code snippet that includes displaying the data in th ...

Verify the middleware is connected to the express endpoint during the unit test

How can I verify that the middleware is properly attached to the route in my unit test below? The server .. var express = require('express'); var http = require('http'); var app = express(); var server = http.createServer(app); var P ...

Error message: Unknown scope- unable to process 'files-path' Android File provider issue

My current project involves implementing file system access in react native Android. However, when attempting to add 'files-path' in XML, an error stating "Error: Unsupported type 'files-path'" is encountered. I am utilizing the react n ...

IntelliJ automation in Java does not allow clicking the button

Currently, I am on the PayPal page and I need to automate clicking the agree button. <form id="ryiForm" class="proceed ng-pristine ng-valid" ng-class="{true: 'validated'}[validated]" ng-submit="confirm.$valid && onPay()" novalidate= ...

Utilizing MVC6 to send both a CSV file and a string to a controller via Ajax

I'm encountering an issue that involves sending a CSV file along with the value of a string variable back to the controller. Individually, I've been successful in sending the file via the form's submit button and the string variable via aja ...

Is it achievable to selectively target a particular class without resorting to utilizing an ID within DOM manipulation?

Is there a way to apply a function to a specific class without requiring an id? For example, in CSS hover effects, where multiple elements share the same class but only the one being hovered over is affected. function toggleHeight(elementId, arrowId) { ...