Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:24:29+00:00 2026-06-11T09:24:29+00:00

I want to do a live search through the table rows, using jQuery, the

  • 0

I want to do a live search through the table rows, using jQuery, the “live” word is the key, because I want to type the keywords in the text input, on the same site and I’d like jQuery to automaticaly sort (or remove those who doesn’t match the search query) the table rows.

Here is my HTML:

<table>
    <tr><th>Unique ID</th><th>Random ID</th></tr>
    <tr><td>214215</td><td>442</td></tr>
    <tr><td>1252512</td><td>556</td></tr>
    <tr><td>2114</td><td>4666</td></tr>
    <tr><td>3245466</td><td>334</td></tr>
    <tr><td>24111</td><td>54364</td></tr>
</table>

And if I would fe. search by the Unique ID, it should show the only rows that starts from the certain number for the Unique ID. Fe. if I would type ‘2’ in the search input box, the following rows should stay, as they begin with 2:

<table>
    <tr><th>Unique ID</th><th>Random ID</th></tr>
    <tr><td>214215</td><td>442</td></tr>
    <tr><td>2114</td><td>4666</td></tr>
    <tr><td>24111</td><td>54364</td></tr>
</table>

If I would type 24, then there should be only one row visible as it begins from the 24:

<table>
    <tr><th>Unique ID</th><th>Random ID</th></tr>
    <tr><td>24111</td><td>54364</td></tr>
</table>

If you guys could give me some tips on how to do something like this I would appreciate it so much.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:24:30+00:00Added an answer on June 11, 2026 at 9:24 am

    I’m not sure how efficient this is but this works:

    $("#search").on("keyup", function() {
        var value = $(this).val();
    
        $("table tr").each(function(index) {
            if (index != 0) {
    
                $row = $(this);
    
                var id = $row.find("td:first").text();
    
                if (id.indexOf(value) != 0) {
                    $(this).hide();
                }
                else {
                    $(this).show();
                }
            }
        });
    });​
    

    DEMO – Live search on table


    I did add some simplistic highlighting logic which you or future users might find handy.

    One of the ways to add some basic highlighting is to wrap em tags around the matched text and using CSS apply a yellow background to the matched text i.e: (em{ background-color: yellow }), similar to this:

    // removes highlighting by replacing each em tag within the specified elements with it's content
    function removeHighlighting(highlightedElements){
        highlightedElements.each(function(){
            var element = $(this);
            element.replaceWith(element.html());
        })
    }
    
    // add highlighting by wrapping the matched text into an em tag, replacing the current elements, html value with it
    function addHighlighting(element, textToHighlight){
        var text = element.text();
        var highlightedText = '<em>' + textToHighlight + '</em>';
        var newText = text.replace(textToHighlight, highlightedText);
        
        element.html(newText);
    }
    
    $("#search").on("keyup", function() {
        var value = $(this).val();
        
        // remove all highlighted text passing all em tags
        removeHighlighting($("table tr em"));
    
        $("table tr").each(function(index) {
            if (index !== 0) {
                $row = $(this);
                
                var $tdElement = $row.find("td:first");
                var id = $tdElement.text();
                var matchedIndex = id.indexOf(value);
                
                if (matchedIndex != 0) {
                    $row.hide();
                }
                else {
                    //highlight matching text, passing element and matched text
                    addHighlighting($tdElement, value);
                    $row.show();
                }
            }
        });
    });
    

    Demo – applying some simple highlighting


    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Jörn Zaefferers autocomplete plugin for jQuery to enable a live search field,
I'm using the jQuery live search plugin by Ryan Heath on my website. I
I want to know the main difference between .live() vs. .bind() methods in jQuery.
i'm trying to make a live search for my mobile website, I don't want
I have a live search input that shows results and lets you use the
I don't understand why $('#searchbox').live prevents my search input to be typed in. I
I am designing a simple jquery live search function within a widget on a
I'm using this PHP Ajax Live Search (http://www.w3schools.com/php/php_ajax_livesearch.asp) and the search results are coming
With the following code: <html> <head> <script type=text/javascript src=jquery-1.7.js></script> <script language=JavaScript> $(document).ready(function(){ $('#cssdropdown li.headlink').hover(
I have a live search facility that narrows down results in a table as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.