jeudi 20 août 2015

3 dynamic checkboxes divs communicating

I am trying to create 3 divs with checkboxes inside that communicate. Following this example http://ift.tt/1PBMefn I would like to be able for exampele to 1]when I check the '1' (which has class A0) to check automatically all checkboxes in the second and third div that also have that same A0 class. Then I'd like to be able to do the same with the third div independently.

<script>
function myFunction(ele){

var cing = ele.className;
//alert(cing);
$('input.'+cing).click(function(){
//alert('2');
  $('input.'+cing).prop('checked',this.checked)
});
}
</script>

<script>
function myFunctionin(elle){
var cinci = elle.className.split(' ')[1];
alert(cinci);
//var cincirr = elle.className.split(' ')[0];
$('input.'+cinci).click(function(){
  $('input.'+cinci).prop('checked',this.checked)
    });

}
</script>

I created the following 2 functions, the first one works correctly, but when I add the third div and the second function I get classes conflicts and I don't know how to do.




Aucun commentaire:

Enregistrer un commentaire