vendredi 13 décembre 2019

On change in a checkbox trigger only once using jquery

I have a simple quiz in which user can answer multiple questions by clicking next, now I want to change the checkbox background when the checkbox is checked

Here is a demo quiz demo

Here is what I have tried

A function to change the background color when checkbox is checked

$("input[type='checkbox']").on('change', function(){
      console.log('clicked');
      if($(this).is(":checked")){
        console.log('Chodzi')
          $(this).addClass("input-before"); 
      }
      else{
        console.log('Nie chodzi');
          $(this).removeClass("input-before");  
      } });

Now when I run my app and click the checkboxes, the checkboxes change the background, but when I click next and then click the checkboxes the background is not changing.

What do I need to change to get this working??




Aucun commentaire:

Enregistrer un commentaire