开发者

Find the Checkbox in Sibling <td> and check it using jQuery

开发者 https://www.devze.com 2023-03-12 05:19 出处:网络
$(\'.answerlabel\').click(function() { $(this).siblings(\'.answer\').find(\'input:checkbox\').attr(\"checked\",\"checked\");
  $('.answerlabel').click(function()
  {
  $(this).siblings('.answer').find('input:checkbox').attr("checked","checked");
  });

There "answer" is one class and "answerlabel" another class.Both will be in same .But it is not working.

Any suggestions.. Here is my HTML Code

 <table>
 <tr>
 <td class="answer"><input tabindex="5" type="checkbox" name="Dum1_5" id="Dum1_5" value="1"/></td>
 <td class="answerlabel"><label for="Dum1_5" id="Dum1_5_label"><table class="sample"><tr><td><img src="http://bizbox.slate.com/blog/google.jpg"></td></tr><tr><td><b>Product 5</b></td></tr><tr><td>Product Description 5</td></tr><tr><td><b>Price 5</b></td></tr></table></label></td>
 </tr&开发者_StackOverflow中文版gt;
 </table>


Try this to get the functionality:

$('.answerlabel label').click(function(){
    $(this).parents('.answerlabel:first').siblings('.answer').find('input:checkbox').attr("checked","checked");
});


  $('.answerlabel').click(function()
  {
  var obj = $(this).siblings('.answer').find('input:checkbox');
  if(obj.attr("checked") =="checked")
  {
      obj.removeAttr("checked");
  }else
  {
        obj.attr("checked","checked");
  }
  });

This will remove the check from the checkbox when it is clicked again. It seems to be working: http://jsfiddle.net/kZNTq/3/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号