Donny
Donny

Reputation: 3

Does hasAttribute() under IE8+ is supported?

I've checked the MDN and Microsoft Websites and they both say Element.hasAttribute() is supported in Internet Explorer from Version 8. I am using hasAttribute in my app and I have created a jsFiddle to test in IE9 just to make sure. This is the fiddle I am using in IE8 and 9 and I am not getting the 2nd alert. Is hasAttribute truly supported or am I missing something? Also this is my first question on here and I've searched to make sure there are no duplicates but if there are I apologize, thank you for any assistance!

EDIT: It would seem that the fiddle only doesn't show the hasAttribute alert in IE9. IE8 yields correct results

<div id="bob">hi</div>

var test = document.getElementById( 'bob' );
alert( test.innerHTML );
alert( test.hasAttribute( 'id' ) );

Upvotes: 0

Views: 507

Answers (2)

RokumDev
RokumDev

Reputation: 367

I make the test in windows 7 with IE 8 and IE9 and works, here are the screenshots.

IE8

IE9

Upvotes: 2

kavetiraviteja
kavetiraviteja

Reputation: 2208

Your code looks perfect ...

If you really want to check whether a particular attr exist or not.... then try like this

if ((element.getAttribute('id') === null) || (element.getAttribute('id') === ''))

Upvotes: 2

Related Questions