Show/hide Select Optgroup Options In Internet Explorer
I have an issue with showing/hiding optgroup options. I tried showing them in Chrome and Internet explorer but never got to a solution that would work on both environments
Solution 1:
display: none
on option elements does not work consistently across browsers. Do not fight this behavior. A better solution is to .remove()
the unwanted optgroup and .append()
it back when necessary.
Solution 2:
Hi friend i wrote the code that is working in IE10..... please verify from your side and let me know if any issue....
<scripttype="text/javascript">if (navigator.appName.toString() == 'Microsoft Internet Explorer') {
var arrOptGroup = $('#state_code optgroup');
var us = $(arrOptGroup[0]).detach();
var ca = $(arrOptGroup[1]).detach();
}
functionvalidateStates(value) {
if (navigator.appName.toString() == 'Microsoft Internet Explorer') {
if (value == 'US') {
$('#state_code optgroup').remove();
$('#state_code').append(us);
}
if (value == 'CA') {
$('#state_code optgroup').remove();
$('#state_code').append(ca);
}
return;
}
var $sel = $('select[name="state_code"]');
if (value == 'US') {
$('optgroup, optgroup > option', $sel).hide();
$('optgroup[label="United States"]', $sel).children().andSelf().show();
console.log('hello there!!');
}
elseif (value == 'CA') {
$('optgroup, optgroup > option', $sel).hide();
$('optgroup[label="Canada"]', $sel).children().andSelf().show();
}
else {
$('optgroup, optgroup > option', $sel).hide();
}
}
</script>
Post a Comment for "Show/hide Select Optgroup Options In Internet Explorer"