Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

radio buttons checked

Why isn't it working ? I am trying to add and remove a class from a label checking if the label related radio input field is checked or not. Thanks :-)

$('input[type="radio"]').change(function() {

     if ($(this).prop('checked')) {	
        $(this).next("label").addClass("checked");
      } else {
          $(this).next("label").removeClass("checked");
      }
 });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In think the value of a check box doesn’t change based on a checked or not.

So you should check event clicked or focus and then validate if it’s checked or not and based on that the class can be changed