I need to have an onclick/hover event on an input tag which is disabled.
Is there another way but to wrap it in another tag and give that tag the events?
<input type="checkbox" onclick="cant_choose('event')" disabled="disabled" value="2" name="enroll_to[event][]">
I need to have an onclick/hover event on an input tag which is disabled.
Is there another way but to wrap it in another tag and give that tag the events?
<input type="checkbox" onclick="cant_choose('event')" disabled="disabled" value="2" name="enroll_to[event][]">
Share
Improve this question
edited May 21, 2012 at 9:51
THelper
15.6k6 gold badges67 silver badges105 bronze badges
asked May 12, 2010 at 13:51
Itay Moav -MalimovkaItay Moav -Malimovka
53.6k67 gold badges196 silver badges290 bronze badges
2 Answers
Reset to default 7You could simulate it being disabled with JavaScript and CSS.
That is, blur all focus it receives, and add a class with something like so.
input.disabled {
background: #d4d0c8;
color: #888;
cursor: default;
}
Update
See it in parison with the normal and browser disabled input box on JSbin.
You could wrap the input field inside a container and bind the click event on it.
<div id='input-container'>
<input id='myText' disabled />
</div>
<script>
$('#input-container').click(function() {
alert('test');
});
</script>
http://jsfiddle/M2EYH/
If you have multiple disabled fields, and don't want to make an unique ID for each container, you can give the containers a class name instead of an ID.