0

I have a listbox with a list of countries and 'ALL COUNTRIES' at the top. I want to disable all of the items except the first if it is selected. I cannot find a way to do this and leave the first item enabled. I also want to be able to click on the first again and have it unselect - is there a way to do this?

 $("#lbCountries").click(function () {
     $("#lbCountires option").each(function (index) {
        if ($(this).is(':selected') && $(this.val() == 'AL') {
            $(this).prop('disabled', false);
         }
         else {
            $(this).prop('disabled', true);
         }
      });
  });

They all get disabled, including the first one. How can I stop that from happening and be able to click on it again and reverse what has been done?

Dean.DePue
  • 1,013
  • 1
  • 21
  • 45

1 Answers1

2

have you tried:

$("#lbCountries").click(function () {
     $("#lbCountires option").not(':first-child').each(function (index) {
        $(this).prop('disabled', true);
      });
  });
Amin Jafari
  • 7,157
  • 2
  • 18
  • 43