How to Perform Real Time Search and Filter on HTML table? Last Updated : 21 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Real-time search and filter on an HTML table lets users quickly find rows by typing in a search box. The table updates instantly, showing only rows that match the search text. To perform a real-time search and filter on an HTML table, add a search box. Use JavaScript to check the input and hide rows that don't match the search text as you type.MethodsDescriptionfilter()This method is used to filter out all the elements that do not match the selected criteria and those matches will be returned. Reduce the set of matched elements to those that match the selector or pass the function's test. toggle()This method is used to check the visibility of selected elements to toggle between hide() and show() for the selected elements. Display or hide the matched elements.Approach to Perform Search and Filter OperationUse jQuery to get the user’s search input, convert it to lowercase, and store it in a variable for case-insensitive comparison.Use JavaScript/jQuery’s filter() and indexOf(value) to check if the search word is in each row. Show or hide rows based on whether the word is found. html <!DOCTYPE html> <html lang="en"> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <style> body { font-family: Arial, sans-serif; text-align: center; } h1 { color: green; } table { border-collapse: collapse; width: 50%; margin: 20px auto; } th, td { border: 1px solid #dddddd; text-align: left; padding: 8px; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3> Perform a real-time search on an HTML table (Entire & Column Specific) </h3> <b>Search the entire table: <input id="entireSearch" type="text" placeholder="Search here"> </b> <br> <b>Search specific column (Course, Duration, or Type): <select id="columnSelect"> <option value="all">All Columns</option> <option value="Course">Course</option> <option value="Duration">Duration</option> <option value="Type">Type</option> </select> <input id="columnSearch" type="text" placeholder="Search column"> </b> <table> <tr> <th>Course</th> <th>Duration</th> <th>Type</th> </tr> <tbody id="geeks"> <tr> <td>C++ STL</td> <td>1499</td> <td>Online Classes</td> </tr> <tr> <td>DSA Foundation</td> <td>7999</td> <td>Regular Classes</td> </tr> <tr> <td>Geeks Classes</td> <td>10799</td> <td>Weekend Classes</td> </tr> <tr> <td>Placement 100</td> <td>9999</td> <td>Online Classes</td> </tr> </tbody> </table> <script> $(document).ready(function () { $("#entireSearch, #columnSearch").on("keyup", function () { let entireValue = $("#entireSearch").val().toLowerCase(); let columnValue = $("#columnSearch").val().toLowerCase(); let selectedColumn = $("#columnSelect").val(); $("#geeks tr").each(function () { let rowText = $(this).text().toLowerCase(); // Show all rows if entire search is empty let matchEntire = entireValue === ""; if (entireValue !== "") { matchEntire = rowText.indexOf(entireValue) > -1; } // Assuming all rows initially match column search let matchColumn = true; if (selectedColumn !== "all" && columnValue !== "") { let columnData = $(this).find("td:nth-child(" + (selectedColumn === "Course" ? 1 : (selectedColumn === "Duration" ? 2 : 3)) + ")").text().toLowerCase(); matchColumn = columnData.indexOf(columnValue) > -1; } $(this).toggle(matchEntire && matchColumn); }); }); }); </script> </body> </html> Output Comment More infoAdvertise with us S SnehashishKalamkar Follow Improve Article Tags : HTML jQuery-Misc Similar Reads How to Create Table in HTML? HTML tables are used for organizing and displaying data in a structured format on web pages. Tables are commonly used for product information, presenting data analytics, or designing a pricing comparison chart. Elements of HTML TableTable ElementsDescription<table>The <table> element def 3 min read How to group the body content in a table using HTML5 ? In this article, group the body content in an <table> element in a document. It is used to define a standard cell in an HTML table. Syntax: <tbody> ... </tbody> Example 1: In this example, we use some HTML tags and make the group the body content in a table. html <!DOCTYPE html 3 min read How create table without using <table> tag ? HyperText Markup Language (HTML) is the standard markup language used to create web pages. HTML allows table creation using the <table> tag. However, tables can also be created in HTML without using <table> tag with the help of Cascading Style Sheet (CSS). CSS is a mechanism for adding s 3 min read What is the rule attribute in HTML Table ? This is an HTML attribute, that is used to specify which parts of the inside borders should be visible. The HTML rule attribute is applicable on table tags. The <table> rules attribute is not supported by HTML 5. Syntax: <table rules="value"> Attributes: This attribute accepts 5 values a 1 min read Why should we avoid use of tables for layout in HTML ? In this article, we will learn why we should avoid using tables for layout in HTML. A website can be divided into various sections comprising of header, menus, content, and footer based on which there are many different layout designs available for developers. Different layouts can be created by usi 4 min read How to fix the height of rows in the table? Fixing the height of rows in a table ensures that all rows have a uniform appearance, preventing them from resizing dynamically based on their content. This approach is useful for maintaining a consistent presentation, especially when dealing with tabular data that needs to be displayed neatly.Here 3 min read How to set the number of rows a table cell should span in HTML ? In this article, we will show how multiple rows are spanned by a table header cell. The task can be done by using the rowspan attribute while using the <th> tag. This property is used to merge one or more cells as well as increase the height of the single header cell automatically. Syntax: 2 min read How to set fixed width for <td> in a table ? The requirement of a table is very normal in the process of designing a web page. HTML provides the <table> tag to construct the table and to define rows and columns <tr> and <td> tags respectively are used. By default, the dimensions of the rows and columns in a table are adjusted 5 min read How to merge table cells in HTML ? The purpose of this article is to explore the method of merging table cells in HTML using the rowspan and colspan attributes. By utilizing rowspan, multiple cells in a row can be merged or combined, while colspan enables the merging of cells in a column within an HTML table. This technique proves es 2 min read How to Create Time-Table Schedule using HTML? A time table or schedule is essential for organizing tasks, events, or classes. Weâll create a basic time-table layout using HTML. A Table is an arrangement of rows and columns. Anyone can create a table by knowing the basics of HTML(HyperText Markup Language). In HTML we can use the <table> t 3 min read Like