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 : .html
Could anyone help me?
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./jquery_evtpaginate/demo_basic.html
Could anyone help me?
Share Improve this question edited Aug 11, 2022 at 10:12 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 18, 2010 at 15:09 rossalerossale 611 gold badge1 silver badge3 bronze badges 3- Can you not just add a class to all those tables? That would probably be quicker and easier. – Dominic Rodger Commented Aug 18, 2010 at 15:12
- Adding a class would be better, but this can be done as is. See Ken Redler's answer. – EndangeredMassa Commented Aug 18, 2010 at 15:13
- The jQuery documentation suggests using this selector in Ken Redler's answer "[...] for identifying elements in pages produced by server-side frameworks that produce HTML with systematic element IDs." rossale might not be able to add classes to the elements. – Justin Rusbatch Commented Aug 18, 2010 at 18:02
3 Answers
Reset to default 14Try this:
$('table[id^=Tab_]')
Padolsey created a good plugin for this. Check it here.
$("table:regex(id, ^Tab)")
this is the best optimized way of doing this.
Use a filter()
:
$('table').filter(function(index){
return this.id.substring(0,4) == 'Tab_';
});