Reputation: 5372
I'd like to enable the textbox when it is clicked. However, when I click the textbox, nothing happens. I believe it is a problem with the jQuery selector. Why isn't this working?
<script>
$(document).ready(function() {
$(':input').click(function() {
$(this).removeAttr('disabled');
});
});
</script>
<input type="text" value="123" disabled="disabled" />
Note: I tried both $('input') and $(':input') to select the textfield. Neither worked.
Upvotes: 0
Views: 450
Reputation: 50115
It has nothing to do with the selector you're using, but rather because, since the input
element is disabled, the events for the input will not fire - see: http://www.jsfiddle.net/DvZDh/
<input type="text" value="123" disabled="disabled" />
<input type="text" value="123" />
The code works on the second input
element, but not the first. A simple solution would probably be to use CSS to simulate the disabled state instead.
Upvotes: 0
Reputation: 626
A disabled input isn't going to fire events. Try changing from disabled to readonly.
Upvotes: 9