ref I got $('a') What is the best way to get

JQuery select element in sibling "td"

HTML

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

I got $('a')

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

+7
jquery
source share
3 answers

You can do it:

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

This matches the <td> value and searches for siblings for the <input> elements.

+14
source share

Another variation

 var input = $('a').closest('tr').find('td input'); 
+6
source share

Try the following:

 $('a').parent().prev().children('input') 
+3
source share

All Articles