views:

42

answers:

3

Hi to all,

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 ???

Thanks a lot.

Alessandro

+6  A: 

Try this:

$('table[id^=Tab_]')
Ken Redler
+1  A: 

Use a filter():

$('table').filter(function(index){
    return this.id.substring(0,4) == 'Tab_';
});
Aaron Digulla
+1  A: 

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

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

this is the best optimized way of doing this.

Teja Kantamneni