admin管理员组文章数量:1419216
<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 ..
<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 ..
Share Improve this question edited Jun 17, 2011 at 9:30 Clement Herreman 10.5k4 gold badges37 silver badges57 bronze badges asked Jun 17, 2011 at 9:27 HussyHussy 2,0294 gold badges25 silver badges32 bronze badges3 Answers
Reset to default 6You 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
you should try in this way..
var nextId = $('#'+first_tr_id ).next("tr").attr("id");
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());
}
本文标签: javascriptHow to get the id of next tr in table using jqueryStack Overflow
版权声明:本文标题:javascript - How to get the id of next tr in table using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745297552a2652169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论