/ / JQuery prochain frère avec case à cocher - jquery, dom, frères et soeurs

JQuery prochain frère avec case à cocher - jquery, dom, frères et soeurs

J'ai du code généré par un outil tiers qui ressemble à ceci:

<tr id="abc0">
<td class="ABC" id="abc0_def">
<input onclick="..." type="checkbox" />
<td class="BodySpacer">
<td class="ABC" id"abc0_hij">
<input onclick="..." type="checkbox" />
<tr id="abc1">
<td class="ABC" id="abc1_def">
<input onclick="..." type="checkbox" />
<td class="BodySpacer">
<td class="ABC" id"abc1_hij">
<input onclick="..." type="checkbox" />

Comme vous pouvez le constater, les tags td ne sont pas correctement fermés et je ne peux pas contrôler cela.

Pour la case à cocher dans le abcX_def comment puis-je cocher automatiquement la case à cocher dans abcX_hij?

J'ai essayé:

var n = $(this).parent().nextAll().has(":checkbox").first().find(":checkbox");
n.attr("checked","checked");

mais cela ne semble pas fonctionner.

Réponses:

0 pour la réponse № 1

Essayer

$(this).closest("tr").find(":checkbox").not(this).prop("checked", $(this).is("checked"))

Démo: Violon