Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable onclick function on image tag

Tags:

jquery

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?

like image 794
user1096909 Avatar asked Dec 30 '11 23:12

user1096909


2 Answers

Try this:

$("#ico_cal_id").prop("onclick", false);

More about prop() here.

like image 178
Purag Avatar answered Sep 22 '22 13:09

Purag


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.

like image 42
alex Avatar answered Sep 21 '22 13:09

alex