getElementById(‘description’) in IE

June 3rd, 2005. Tagged: JavaScript

document.getElementById() in IE has some issues. The problem can be spotted when you have a page element with an id "description" and meta tag with a name "description" IE considers the meta tag to be the one that should be returned by getElementById(). Which is, of course, wrong. ID is an ID and name is a totally different thing.

Anyway, heads up for that IE behaviour.

As an illustration, here in WordPress (the blogging tool that powers the page you're reading) there's a meta tag, called "generator", like this:
<meta name="generator" content="WordPress 1.5" />

So if you do:
alert(document.getElementById('generator'))
this will return null in FireFox, the way it was meant to be (by w3c, that is) and in IE, you'll get [Object]

Try it...
Try it with the "content" property...
(The second example will give an error in FireFox as there is no "content" property of null.

Tell your friends about this post: Facebook, Twitter, Google+

Sorry, comments disabled and hidden due to excessive spam. Working on restoring the existing comments...

Meanwhile, hit me up on twitter @stoyanstefanov