Reputation: 396
How do I select just a table with class d with jquery selectors. For some reason this code won't work properly...
var dTableTags = $(".d table");
example table would be...
<table id="thetable" class="d">
<thead>
<tr><th>Column 1 header</th><th>Column 2 header</th></tr>
</thead>
<tbody>
<tr><td>Column 1 data</td><td>Column 2 data</td></tr>
</tbody>
</table>
Upvotes: 6
Views: 32795
Reputation: 2214
If you have an ID property/attribute set on the element, why are you selecting by class, anyways? Selecting by ID is much better if you're trying to select something in a distinct fashion. CSS classes can be shared, but the ID property, not so much.
Thus, your selector should be $('#thetable')
Anything else is superfluous really.
Upvotes: 0
Reputation: 54087
Your selector is wrong; try $("table.d")
instead.
The jQuery documentation does not explain this directly, it defers to the W3C CSS selector documentation which is a lot more comprehensive.
Upvotes: 18
Reputation: 55740
You are trying to search for table that is inside class d Which is wrong ..
Change your selector to this
$("table.d"); // Because the table has the class d
Upvotes: 3