Adrenaxus
Adrenaxus

Reputation: 1613

Cross-browser hiding of disabled="disabled" <option>

Is there a reliable way (CSS, JQuery, etc.) to completely hide a disabled <option disabled="disabled"> on all major browsers?

I need it to be completely hidden instead of being only greyed out (like in IE).

UPDATE: There is no crossbrowser way of hiding disabled options. If you need an option removed, use Jquery's detach() as pointed out below by Kevin B. disabled options are no good thing.

Upvotes: 0

Views: 402

Answers (2)

Kevin B
Kevin B

Reputation: 95026

Yes, remove it from the select until you want to show it.

var options = $("#myselect option");

// to disable the option at index 3

options.eq(3).detach();

// to enable the option at index 3

options.eq(3).insertAfter(options.eq(2)); // assuming option at index 2 is still attached to the DOM

DEMO

Upvotes: 2

Johan
Johan

Reputation: 19062

Or maybe this

$('option[disabled="disabled"]').remove()​

Upvotes: 0

Related Questions