Using JQuery Create a Filter/Search HTML Table

Beginner 5 views Jul 07, 2026

Learn how to create a filter/search HTML table using JQuery code. This beginner-friendly tutorial will guide you through the process step-by-step.

Create a Filter-Search HTML Table with JQuery Create a Filter-Search HTML Table with JQuery

When you have a large list of records, it is helpful to display them in an HTML table. This makes it easy to view and sort the data. However, if the list is too large, it can be difficult to find the information you are looking for. One way to solve this problem is to allow users to search for text within the table.

Introduction

In this tutorial, we will learn how to perform a real-time search and filter an HTML table. When a user enters a word, all rows in the table (except the table header) will be searched and the rows containing the matching word will be displayed.

Filterable HTML tables can be beneficial for users by improving the user experience and making it easier to navigate large amounts of data. They can be created with just a few lines of code.

Let's start making these Filter/Search HTML Table using HTML, CSS and JavaScript(JQuery) step by step.

Prerequisites:

To follow this tutorial, you should have a basic understanding of the following technologies:

  • HTML: Hyper Text Markup Language is the language used to create web pages.
  • CSS: Cascading Style Sheets is used to style web pages.
  • JavaScript: JavaScript is a programming language that can be used to add interactivity to web pages.

You will also need a code editor to write and save your code. Some popular code editors include:

  • Visual Studio Code: A free and open-source code editor developed by Microsoft.
  • Sublime Text: A commercial code editor that is popular for its speed and flexibility.

Once you have the necessary knowledge and tools, you can start following this tutorial.

Read Also: Creating a Simple Calculator using HTML and Pure CSS

Source Code

Step 1

The first thing we need to do is create our HTML file. In the HTML file, create an input element with an id name "search" for the search box and create your table element with an id name "tab". Also, In head section of your HTML page paste JQuery library script tag. Without this script tag, your function will not work.

After creating the files just paste the following below codes into your file. Make sure to save your HTML document with a .html extension, so that it can be properly viewed in a web browser.

This is the basic structure of our search table using HTML, and now we can move on to styling it using CSS.


    
      
        Home
        
        
        
        
      
      
        
       

Myritebook - Learning Tutorials

        Search the table for Name, Location or Age:                      
       
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
NameLocationAge
Ben ChenChina41
Bob WhiteCanada55
Carlo SilvaItaly47
Clara LeeSouth Korea19
Elodie NguyenFrance33
Jenny MillerAustralia22
Julius KaplanGermany37
Leena AhmedIndia29
Maria RodriguezMexico24
Peter JacksonSouth Africa21
   
         

Step 2

The given CSS styles are optional for the table. Anyhow, you can use the following CSS styles if you want to beautify the HTML table.

table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 55%;
}

td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

h1 {
color: green;
}

Step 3

Finally, add the following JQuery function into your project for table search filter.

Once you have linked JQuery to your HTML document, you can add the following JQuery function to your project to create a table search filter. The function will set up an event listener for the input element with an ID of "search". When a user types in the input field, the table rows will be filtered based on the input value.

Create a JavaScript file with the name of script.js and paste the given codes into your JavaScript file and make sure it's linked properly to your HTML document, so that the scripts are executed on the page. Remember, you’ve to create a file with .js extension.

$(document).ready(function() {
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
        $("#tab tr").filter(function() {
            $(this).toggle($(this).text()
                .toLowerCase().indexOf(value) > -1)
        });
    });
});

 

Conclusion

In this tutorial, we've shown you how to create a filterable/searchable HTML table with just a few lines of JQuery code. By following the steps we've outlined, you can make navigating large amounts of data much easier for users. We hope you found this tutorial helpful and encourage you to try creating a filterable table yourself.
 

I hope you enjoyed this post. Now, with these examples, you can create your own amazing page.

Did you like it? Let me know in the comments below.

And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!

Technologies Used

CSS HTML JavaScript

Live Output

See the project in action below. This is the live preview of the code you just learned.

Output Preview

No code found to display in live output.

Make sure your post contains HTML, CSS, or JavaScript code blocks with proper language labels.