<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>
Dites, j'ai un <table>
qui contient un couple <tr>
comme celui ci-dessus. Parmi les <tr>
, il n'y en a qu'un qui a <span id="home_location_indicator">(Home)</span>
.Quelle est la meilleure approche pour atteindre un autre nœud ayant un grand-parent commun comme nœud actuel?
Je suis en train de décider de l'approche à prendre pour récupérer la valeur de l'entrée name="location_select"
qui appartient à la <tr>
contenant <span id="home_location_indicator">
.
Voici les deux approches que je peux penser à:
$("tr").has("#home_location_indicator").find('input[name="location_select"]').val()
$("#home_location_indicator").parents("tr").find('input[name="location_select"]').val()
Lequel est une meilleure approche? Et pourquoi? Ou est-ce important?
Yup .. '.closest' est mieux que' .parents' http://jsperf.com/closest-vs-parents –