Hey im trying to access a specific row. I have the id attr of the tr I wan't to get.
My table looks like this:
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr id="1" class="odd">
<td class=" sorting_1">bla</td>
</tr>
<tr id="3" class="even">
<td class=" sorting_1">hej</td>
</tr>
<tr id="4" class="odd row_selected">
<td class=" sorting_1">sdf</td>
</tr>
<tr id="8" class="even">
<td class=" sorting_1">testgfdgvcxbvcbcv</td>
</tr>
<tr id="9" class="odd">
<td class=" sorting_1">testgfdgvcxbvcbcvfdgsgfdgdfs</td>
</tr>
</tbody>
Here i need to access But I can't figure out how to access this.
Well, you should usually avoid having numeric-only id's (unless you are using 100% HTML5!). And you should definately make sure id's are unique on your page.
But you should be able to use jquery selector
$('#1')
Assuming you're not using HTML5, then you should change your markup to use a more standard ID:
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr id="row1" class="odd">
<td class=" sorting_1">bla</td>
</tr>
<tr id="row3" class="even">
<td class=" sorting_1">hej</td>
</tr>
...
Then you would access a particular row using
$('#row1')
You can retrieve any element, where you have the ID, using
$("#ID")
So in your case it's
$("#1")
This will return you the jQuery Object of the underlying HTML element, in your case the tr element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With