1

There is a difference between IE10 and other browsers with disabled attribute in tag.

<!DOCTYPE html>
<html>
<head>
    <title> Img Tag </title>
</head>
<body>
    <script type="text/javascript">
        function abc() {
            alert("Hi");
        }
    </script>
    <img style="width: 50px; height: 50px;" onload="abc()" onclick="abc()"  src="./testimg.png" disabled />
 </body>
</html>

IE10 is respecting disabled property and both onload & onclick not firing. If I remove disabled attribute, it is firing both the events.

But, Chrome is not not respecting the disabled property. I mean, it is firing both the events, irrespective of disabled attribute.

My question is, Can I use disabled property in tag? if yes, What is the correct behavior, IE10 or Chrome? is it a bug in cherome?

llanato
  • 2,508
  • 6
  • 37
  • 59
  • `disabled` only works on form elements. – Vucko Apr 08 '14 at 10:09
  • Vucko please check this link: http://www.java2s.com/Code/JavaScriptReference/Javascript-Properties/disabledisappliedto.htm – Mohammed Imran Khan Apr 08 '14 at 10:11
  • @Mohammed Imran Khan: That's for JavaScript properties, not HTML attributes. – BoltClock Apr 08 '14 at 10:22
  • 1
    `disabled` is not valid for `img` elements check the [HTML5 specs: The img element - Content attributes](http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-img-element). If vendors change the behavior of the `img` element when `disabled` is added, then they don't behave correctly. The closest thing would probably be [aria-disabled](http://www.w3.org/TR/wai-aria/states_and_properties#aria-disabled). – t.niese Apr 08 '14 at 10:23

2 Answers2

1

No specification or public draft allows disabled for the a element. So Chrome is right and IE is wrong. Interestingly, documentation of a element on IE does not mention the disabled attribute (only the isDisabled property).

Cf. How to disable HTML links.

Community
  • 1
  • 1
Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
0

In the HTML 5 specification:

The correct behaviour for non-standard attributes is to add them to the DOM but to otherwise ignore them. Therefore Chrome has the correct behaviour.


Images are not interactive controls, so it is generally a bad idea to bind click events to them.

Use a button element instead. You can place an image inside it and style the button so it looks like a plain image. You can disable the button and bind a click event to it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Images not being interactive controls seems pretty much a statement of your taste not a fact. What would be the disadvantage of binding a handler to the onclick event of an img element. – Mircea Ion Jul 29 '16 at 01:58