开发者

jQuery select element in sibling's "td"

开发者 https://www.devze.com 2022-12-26 01:45 出处:网络
HTML is <tr> <td><input /></td> <td><a>ref</a></td> </tr>

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

精彩评论

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