admin 管理员组文章数量: 1086019
Lets say I have something like this:
<tr>
<td><input type="text" /></td>
<td>Somevalue</td>
<td><intput type="text /></td>
</tr>
I am in the event handler for a keypress in the first text box. I want to find the next td which has a text box in it if it exists using jQuery.
Lets say I have something like this:
<tr>
<td><input type="text" /></td>
<td>Somevalue</td>
<td><intput type="text /></td>
</tr>
I am in the event handler for a keypress in the first text box. I want to find the next td which has a text box in it if it exists using jQuery.
Share Improve this question asked Mar 5, 2009 at 15:53 Ross GoddardRoss Goddard 4,3124 gold badges28 silver badges24 bronze badges3 Answers
Reset to default 6Something like this should work (assuming this
is the input).
var next = $(this).parent().next("td > input[type='text']");
tj111's answer does not work for me. May be that is because of newer version of jQuery. I came up with this:
var next = $(this).parent().nextAll().has("input[type='text']").first();
I don't know what is your selector, but if you need to select all inputs (type text). You can try this.
$(function(){
$(':input').each(function(){
$(this).keypress(function(){
$(this).next('input[type=text]').val('I\'m the next');
}) // end of keypress
}) // enf of each
}) // End of function
So, do not matter where you put more inputs, you can always take them.
本文标签: javascriptjQueryFind the next element which has a specific childStack Overflow
版权声明:本文标题:javascript - jQuery - Find the next element which has a specific child - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743998744a2516057.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论