tags:

views:

48

answers:

3

HTML is

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

I got
$('a')

What is the most optimal way to get <input /> from this ?
If they are together <input /><a></a>, i can use $('a').sibling('input'), but they are in different td's

A: 

You can do this:

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

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

Nick Craver
A: 

Try this:

$('a').parent().prev().children('input')
Gumbo
+1  A: 

Another variation

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