Tuesday, May 6, 2008

IE Dom and Custom HTML Tags

I've been doing some HTML DOM parsing do deal with JSON return values and decided it would be quicker to use document.getElementsByTagName('myCustomTag') to get just the pieces I wanted.

This works fine, except in Internet Explorer. It finds only the opening tag, and says that it has no children. Of course, the other browsers did it right and it works fine.

So, the trick you have to do with IE to make this work has to do with the HTML namespaces.

In your <html> tag, include xmlns:blah=http://www.blah.com (obviously customizable)

Then name your custom tags like this ... instead of just ....

Now, when you do a document.getElementsByTagName('MyTag')[0] you'll get a full-fledged DOM object with children, etc. It's not the most obvious thing to do, but it works.

0 comments: