Reputation: 13975
I am wondering if there is a way to NOT show the disabled elements? And if they we're re-enabled (by javascript/jquery) show them?
Upvotes: 2
Views: 1335
Reputation: 72971
You could do the following in jQuery, assuming you use the proper HTML attibrute for your input
tags:
$('input[disabled="disabled"']).hide();
Then just add a show()
to your jQuery code that re-enables them.
I failed to reference the question title. The above is a solution for form input
tags, not select option
tags.
Upvotes: 0
Reputation: 17084
Wrap it with a span that hides the element. Not pretty, but it works. E.g.
jQuery
$(document).ready(function() {
$("#togglebutton").click(function(){
var Element=$("#disableme");
if (Element.attr("disabled")==false) {
Element.attr("disabled","disabled").wrap("<span class='hide'></span>");
} else {
Element.removeAttr("disabled");
Element.parent('span.hide').replaceWith(Element.parent('span.hide').html());
}
});
});
CSS
.hide {
display: none;
}
HTML
<input type="text" id="disableme"><br />
<input type="button" id="togglebutton" value="Toggle disable">
Tested on IE 6, IE 8, Firefox 3.6.6, Opera 10.60 and Iron 5.0.380.
Upvotes: 2
Reputation: 19812
In CSS you can do the following.
option[disabled]
{
display:none;
}
Which should hide options that are disabled, not sure about browser compatibility.
Upvotes: 0