Search code examples
javascripttablerowlivesearch

live search for a substring in a table in javascript


I have been testing this code which I found on the Internet http://jsfiddle.net/FranWahl/rFGWZ/ but what I really want to do is to search for a substring in the table row. For example if I had this table

<table>
<tr><th>Unique ID</th><th>Random ID</th></tr>
<tr><td>214215</td><td>442</td></tr>
<tr><td>1252512 ab</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>

I would like to search for "ab". Is this possible ? and with which function?


Solution

  • Change the following line:

    if (id.indexOf(value) !== 0) {
    

    to

    if (id.indexOf(value) === -1) {