jquery Tree Traversal prev() in TD's

Posted by Guido Lemmens on Stack Overflow See other posts from Stack Overflow or by Guido Lemmens
Published on 2010-03-11T22:22:25Z Indexed on 2010/03/12 8:37 UTC
Read the original article Hit count: 442

Filed under:
|

Hello,

I'm trying to check/unckeck a selectbox by jquery in a previous TD. I have tried for hours several combination with prev(), parent(), closest(), but still without result... Here is the example code:

<table>
 <tr>
 <td><input type="checkbox" class="resultcheck"></td>
 <td><label class="resultchecklabel">Text 1</label></td>
 </tr>

 <tr>
 <td><input type="checkbox" class="resultcheck"></td>
 <td><label class="resultchecklabel">Text 2</label></td>
 </tr>

</table>

<script>
$('.resultchecklabel').live('click', function() {
 if ($(this).prev('td input:checked').val() != null) 
 {
  $(this).prev('td').prev("input").removeAttr("checked");
 }
 else
 {
  $(this).prev('td').prev("input").attr("checked","checked");
 }
});
</script>

Who can help me to solve this question? Many thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about traversal