0

I have this checkbox code

<div class="checkbox-group">

    <label class="fc-contain-sm checkbox-status">
        <input type="checkbox" class="formjs-checkbox-sm" checked disabled>
        <div class="fc-status-sm"></div>
        <span class="checkbox-lable-sm">Disabled checkbox</span>
    </label>

    <label class="fc-contain-sm checkbox-status">
        <input type="checkbox" class="formjs-checkbox-sm">
        <div class="fc-status-sm"></div>
        <span class="checkbox-lable-sm">Normal checkbox</span>
    </label>

</div>

And i want to add class disabled to checkbox-lable-sm class if the checkbox is disabled using jquery

css

.checkbox-group .disabled {
  cursor: not-allowed;
}

I have tried this code but it is not working

$('.checkbox-group > input:disabled.formjs-checkbox-sm').each(function(){
    $(this).find('.checkbox-lable-sm').addBack().addClass("disabled");
}); 
1
  • I'm confused, you say "Add class for label" but your code shows your trying to add it to the span ? Commented Feb 7, 2017 at 11:05

2 Answers 2

1
$('.checkbox-group input:disabled.formjs-checkbox-sm').each(function() {
    $(this).parent().find('.checkbox-lable-sm').addClass("disabled");
}); 
Sign up to request clarification or add additional context in comments.

Comments

1

Give it a try to this,

$(".checkbox-group input[type='checkbox']").each(function() {
  if ($(this).is(':disabled')) {
    $(this).closest(".fc-contain-sm").find(".checkbox-lable-sm").addClass("disabled");
  }
});

I am sure this will work.

Here is working jsfiddle

Here is second way,

$(".checkbox-group input[type='checkbox']:disabled").each(function() {
  $(this).closest(".fc-contain-sm").find(".checkbox-lable-sm").addClass("disabled");
});

Here is third way,

$(".checkbox-group input[type='checkbox']:disabled").each(function() {
  $(this).closest("label").find(".checkbox-lable-sm").addClass("disabled");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.