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 ?
<input /><a></a>
, i can use $('a').sibling('input')
, but they are in different td'sYou 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')
精彩评论