random-forest-cat
random-forest-cat

Reputation: 36002

src vs href on img tag IE

I have run into an issue IE 8 and IE 11 is treating src and href as the same thing for img tags -

http://codepen.io/anon/pen/YXqzrV

<img id="logo" alt="Rent.com" src="http://rent.qa.assets.rentpathcdn.com/assets/rent-logo-eb029594.png">

var a = document.getElementById('logo');
alert(a.src);
alert(a.href);

this occurs when I do not have an href attribute specified for img node, just a src.

I'm writing a custom extension that collects information about a clicked node. is there a potential work around for this issue, or will I have to code around the non existent attributes?

Upvotes: 2

Views: 578

Answers (1)

beautifulcoder
beautifulcoder

Reputation: 11340

IE does not support href in img HTML elements.

The img element does not support the HREF content attribute. In addition, the href property is read-only for the img Document Object Model (DOM) object.

https://msdn.microsoft.com/en-us/library/cc848861(v=vs.85).aspx

I would stick to what @Frederic mentioned above and use a.getAttribute('href') instead.

Upvotes: 2

Related Questions