1

How does one dynamically enable and disable the button when the checkbox is checked and unchecked in semantic UI, I've spent so much time to do this.

Here is the html

<div class="ui fitted checkbox">
<input type="checkbox" > <label></label>
</div>
<div class="ui small positive disabled button" id="edit">
<i class="edit icon"></i> Edit
</div>

Here is my javascript

<script>
    $(document).ready(function () {
                    if (
                    $('#cek').checkbox({
                        onChecked: function () {
                        }
                    })) {
                        $('#edit').removeClass('disabled');
                    } else {
                        $('#edit').addClass('disabled');       
                    }
                });
</script>

Please help, it drives me crazy.

1 Answer 1

1

Use toggleClass() like

 $(document).ready(function() {
             $('[type="checkbox"]').change(function() {
                     $('#edit').toggleClass('disabled');
                 });
             });

This will add the class if it does not exist or remove it if it does.

$(document).ready(function() {
      $('[type="checkbox"]').change(function() {
         
          $('#edit').toggleClass('disabled');
        });
      });
.disabled {
  color: gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="ui fitted checkbox">
  <input type="checkbox" />
  <label></label>
</div>
<div class="ui small positive disabled button" id="edit">
  <i class="edit icon"></i> Edit
</div>

Sign up to request clarification or add additional context in comments.

7 Comments

@AudioAlief, sorry there was a syntax error. See it now
@AmmarCE, i appriciate your code man,but in semantic, to make the checkbox is checked you must add the js something like : $('ui.checkbox').checkbox(); , so if i use your code,i must remove the <div class=ui fitted button></div> , and left the checkbox unstyled
@AudioAlief, thats fine, include $('ui.checkbox').checkbox(); before my code and it should work
$('ui.checkbox').checkbox(); $(document).ready(function() { $('[type="checkbox"]').change(function() { $('#edit').toggleClass('disabled'); }); }); thats all didnt work, i swear :(
no need to apologize , i appriciate your answer man,it was helpful,really ,thank you so much brother :D
|

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.