Reputation: 2029
<table>
<tr id ="tr_id_1">
<td >
Blah
</td
<td>
Blah
</td>
</tr>
<tr id ="tr_id_2">
<td>
Blah
</td>
<td>
Blah
</td>
</tr>
</table>
i have got the id of first tr using jquery
var first_tr_id = tr_id_1 // id of first tr
now by using this id how to get the id of next tr i have tried like this
var nextId = ('#'+first_tr_id ).next("tr").attr("id");
but its giving ("#" + row_id).next is not a function error ..
Upvotes: 1
Views: 4276
Reputation: 4136
You have a problem in assigning a variable:
var first_tr_id = tr_id_1
it should be inside quote
var first_tr_id = "tr_id_1"
Also, to get all the IDs, you can use the following code:
$("table tr").each(function(index) {
alert($(this).id());
}
Upvotes: 0
Reputation: 11028
you should try in this way..
var nextId = $('#'+first_tr_id ).next("tr").attr("id");
Upvotes: 0
Reputation: 10536
You code lacks the jQuery $
var nextId = $('#'+first_tr_id ).next("tr").attr("id");
Also an id is a string, so you should set your variable like so :
var first_tr_id = 'tr_id_1'; // id of first tr
Upvotes: 6