Click here to Skip to main content
13,258,238 members (37,632 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 28 Dec 2012

Filter HTML table

, 27 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Select only those rows in table which meet search criteria.


In this post I will tell you how you can filter an HTML table using jQuery.  

Using the code

All you need is create an HTML table and a textbox. The search function will be called on the textbox's onkeyup event. Here is the function: 

function Search() {
    var value = $('input[id$="txtSearch"]').val();
    if (value) {
        $('#MyTable tr:not(:first)').each(function () {
            var index = -1;
            $(this).children('td').each(function () {
                var text = $(this).text();
                if (text.toLowerCase().indexOf(value.toLowerCase()) != -1) {
                    index = 0;
                    return false;
            if (index == 0)
        $('#MyTable tr').show();
<input type="text" onkeyup="Search()" id="txtSearch" /> 

This function checks if the input criteria matches the text of any td, it makes the row visible and if input criteria is not found in whole row, then that row is hidden. If there is no value in input criteria all table rows are displayed. 

This is a very basic code. Any suggestions will be greatly appreciated. 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer F3 Technologies
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

Questionhighly inefficient code Pin
Seishin#30-Dec-12 23:21
memberSeishin#30-Dec-12 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 27 Mar 2013
Article Copyright 2012 by MairajAhmed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid