jeudi 21 février 2019

how to correct check checkbox and display if is checked

i use this code to show some text (Checked) when click on 1 or more checkboxes. I use the on because the checkboxes are dynamically created.

It seems that only IE Edge can not deal with it. I have to click twice on a checkbox to show the Checked text. In all other browsers it works immediately. Really don't know what is wrong with the code

<input type="checkbox" class="rafcheckbox" value="1" />
<input type="checkbox" class="rafcheckbox" value="2" />
<input type="checkbox" class="rafcheckbox" value="3" />

<div class="cb-buttons" style="display:none">Checked</div>

<script>

$(document).on('click','.rafcheckbox',function() {  
  var $checkboxes = $('.rafcheckbox').change(function() {

    var anyChecked = $checkboxes.filter(':checked').length != 0;
    $(".cb-buttons").toggle(anyChecked);
  });
});

</script>




Aucun commentaire:

Enregistrer un commentaire