Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Select all tables with id starting by

I would like to select all the tables where the id starts with the same sentence, with jQuery.

This what I mean:

<table id="Tab_01">
    <tr>
        <td>....
    <tr>
    ....
</table>

<table id="Tab_02">
    <tr>
        <td>....
    <tr>
    ....
</table>
<table id="Tab_03">
    <tr>
        <td>....
    <tr>
    ....
</table>
<table id="xyz">
    <tr>
        <td>....
    <tr>
    ....
</table>

What I need, is to select the tables that start with "Tab_" and not the table with id = "xyz"

I would like to use this code for making a similar navigation with this plugin : http://projects.allmarkedup.com/jquery_evtpaginate/demo_basic.html

Could anyone help me?

like image 292
rossale Avatar asked Aug 18 '10 15:08

rossale


3 Answers

Try this:

$('table[id^=Tab_]')
like image 76
Ken Redler Avatar answered Nov 13 '22 10:11

Ken Redler


Padolsey created a good plugin for this. Check it here.

$("table:regex(id, ^Tab)")

this is the best optimized way of doing this.

like image 27
Teja Kantamneni Avatar answered Nov 13 '22 11:11

Teja Kantamneni


Use a filter():

$('table').filter(function(index){
    return this.id.substring(0,4) == 'Tab_';
});
like image 35
Aaron Digulla Avatar answered Nov 13 '22 12:11

Aaron Digulla