开发者

jQuery select element in sibling's "td"

HTML is

<tr>  
    <td><input /></td>  
    <td><a>ref</a></td>  
</tr>

I got

$('a')

What is the most optimal way to get <input /> fr开发者_StackOverflow社区om this ?

If they are together <input /><a></a>, i can use $('a').sibling('input'), but they are in different td's


You can do this:

$('a').closest('td').siblings().find('input')

This goes up to the <td>, and searches siblings for <input> elements.


Another variation

var input = $('a').closest('tr').find('td input');


Try this:

$('a').parent().prev().children('input')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜