<tr>
<th scope="row">
<span id="home_location_indicator">(Home)</span>
</th>
<td>
<span class="postal_code_display">...</span>
</td>
<td><input value="1" name="location_select" type="radio" /></td>
</tr>
私は<tr>
のように上記のような<table>
を持っています。 <tr>
のうち、<span id="home_location_indicator">(Home)</span>
を持つものは1つだけです。現在のノードとして共通の祖父母を持つ別のノードに到達するためのよりよいアプローチは何ですか?
私は<span id="home_location_indicator">
を含む<tr>
に属し入力name="location_select"
の値を取得するために取ることのアプローチを決定しようとしています。 1がより良いアプローチです
$("tr").has("#home_location_indicator").find('input[name="location_select"]').val()
$("#home_location_indicator").parents("tr").find('input[name="location_select"]').val()
:ここ
は、私は考えることができる2つの方法がありますか?なぜ?それとも問題なの?
うん.. '.closest'は' .parents'よりも優れているhttp://jsperf.com/closest-vs-parents –