Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery : Get row by tr 'id' [closed]

Tags:

jquery

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.

like image 248
Mikkel Nielsen Avatar asked Nov 30 '12 08:11

Mikkel Nielsen


2 Answers

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')
like image 168
Jamiec Avatar answered Oct 24 '22 07:10

Jamiec


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.

like image 31
akohout Avatar answered Oct 24 '22 09:10

akohout