jQuery how can I disable a click on <img>
tag
$("#ico_cal_id").attr('disabled', 'disabled') or
$("#img_id").attr('disabled', 'disabled') is not working
Below is my code:
<span id="img_id"><src="ico_calendar.png" id="ico_cal_id" style="cursor: pointer"; onlick="showCalendar(this,'startDay','startMonth','startYear');" /></span>
whenever I click on the calendar_image the calendar is popping up
Any ideas?
Try this:
$("#ico_cal_id").prop("onclick", false);
More about prop()
here.
img
elements do not have a disabled
attribute, so setting it won't affect its behaviour.
You could prevent the event from bubbling and from executing other handlers with event.stopImmediatePropagation()
...
$("#ico_cal_id").click(function(event) {
event.stopImmediatePropagation();
});
Alternatively, you could use $("#ico_cal_id").removeAttr("onclick")
if the event is always being attached inline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With