2

please check at first Jsfiddle: http://tinyurl.com/q58dnpo this little script works exactly how I imagined. It allows you to check just one checkbox and it dynamically syncs the checkboxes. So far so good.

BUT after pasting it into a more complex script the sync-function just works exactly one time clicking A,B and C. check it out here: http://tinyurl.com/ngbj2yk

is there something wrong with the header? I am really clueless, because on Jsfiddle all works fine even the more complex code (probably I am just a noob ;))

Thanks!

Jonas
  • 121,568
  • 97
  • 310
  • 388
user3439585
  • 77
  • 1
  • 8

2 Answers2

4

Everywhere you're currently using

$(element).attr("checked","checked");

change it to

$(element).prop("checked", true); // or false

as element.checked is a property, and the prop() method is the proper method to use, attr() will only change the attribute and cause the issues you're experiencing.

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

You should use .prop() instead of .attr()

The following jQuery code should work just fine:

$(document).ready(function(){
    $('#eins').click(function(){
        $("#gruppe1").prop("checked", true);
    });

$('#zwei').click(function(){
        $("#gruppe2").prop("checked", true);
    });

$('#drei').click(function(){
        $("#gruppe3").prop("checked", true);
    });
});

Resources:

Community
  • 1
  • 1
martynas
  • 12,120
  • 3
  • 55
  • 60