JQuery Hide Option doesn't work in IE and Safari

后端 未结 7 2033
天命终不由人
天命终不由人 2020-11-30 09:58

I\'m trying to hide a few options in a dropdown box using .hide(). This works perfectly fine in firefox and chrome, but it doesn\'t work in IE and Safari. My original code i

7条回答
  •  感动是毒
    2020-11-30 10:33

    I tried in many different ways but this solution seems reasonable and I have used in my code. No plugins required simple register function with jquery object

    Solution at glance:

    (function ($) {
    
    
    $('#showOne').click(function () {
        $('#ddlNumbers').showHideDropdownOptions('3', true);
    });
    
    $('#hideOne').click(function () {
        $('#ddlNumbers').showHideDropdownOptions('3', false);
    });
    
     $.fn.showHideDropdownOptions = function(value, canShowOption) { 
    
             $(this).find('option[value="' + value + '"]').map(function () {
                return $(this).parent('span').length === 0 ? this : null;
            }).wrap('').hide();
    
            if (canShowOption) 
                $(this).find('option[value="' + value + '"]').unwrap().show();
            else 
                $(this).find('option[value="' + value + '"]').hide();
    
    }
    
    
    
    })(jQuery);
    

    Here is the complete implementation http://jsfiddle.net/8uxD7/3/

提交回复
热议问题