Disable options in IE with jQuery

IE still does not support the disabled attribute for select options. Here is a fix for that - implemented with jQuery and a little help of my good friend hEcki :)

$(document).ready(function(){
  // Disabled options fix for Internet Explorer
  $('select').each(function(){
    this.rejectDisabled = function(){
      if (this.options[this.selectedIndex].disabled){
        if (this.lastSelectedIndex) {
          this.selectedIndex = this.lastSelectedIndex;
        } else {
          var first_enabled = $(this).children('option:not(:disabled)').get(0);
          this.selectedIndex = first_enabled ? first_enabled.index : 0;
        }
      } else {
        this.lastSelectedIndex = this.selectedIndex;
      }
    };
    this.rejectDisabled();
    this.lastSelectedIndex = this.selectedIndex;
    $(this).children('option[disabled]').each(function(){
      $(this).css('color', '#CCC');
    });
    $(this).change(function() {
      this.rejectDisabled();
    });
  });
});
iPhone app for GitHub

iOctocat

is GitHub in your pocket: The go to app for staying up to date with your projects on your iPhone, and iPod Touch.
It is