Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery select element in sibling's "td"

Tags:

jquery

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

like image 883
Qiao Avatar asked Apr 09 '10 20:04

Qiao


3 Answers

Try this:

$('a').parent().prev().children('input')
like image 183
Gumbo Avatar answered Nov 16 '22 00:11

Gumbo


You can do this:

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

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

like image 44
Nick Craver Avatar answered Nov 15 '22 23:11

Nick Craver


Another variation

var input = $('a').closest('tr').find('td input');
like image 45
Sky Sanders Avatar answered Nov 16 '22 00:11

Sky Sanders