vendredi 24 avril 2015

adding removing classes for checkbox and drop down

I am adding and removing class to the elements on change event. The below code is working for dropdown and radio buttons, but is not working for checkbox and dropdown. The disable class gets applied, but on unchecking it is not getting enabled..

$(function() {
  $switchers.each(function(index, elem) {
    $(elem).prop("disabled", false).removeClass("c_disabled")
        .closest(".wrapper")
        .find(".overlay").remove();

    if ($(elem).prop('tagName') == 'SELECT') {          
        $(elem).children().removeClass('dis').removeAttr('disabled');
    }
  });

How can I make it work for checkbox's check, uncheck.

For example, If you see my fiddle when you check C3, dropdown option Two gets disabled, but when you uncheck it, it doesn't get enabled again, It gets enable while you uncheck other checked checkbox.

What is the reason for this? When I have a combination of radio and dropdown it works for that.

I want it to enable it once I uncheck C3

It has anything to do with the point of checkbox being multiselect?

I am able to check If the options are checked or unchecked with the below code.

    $(".checkdrop").on("change", function(e) {
  var $this = $(this);
      var ischecked = e.target.checked;
      if(ischecked) {
        alert("checked it");

      }
      else
      {
        alert("unchecked it");

       //$(elem).removeClass('c_disabled').removeAttr('disabled');
      } 
});

Here is my fiddle

Please help.




Aucun commentaire:

Enregistrer un commentaire