Email

Wednesday, April 18, 2007

Attribute nightmare in IE

clipped from tobielangel.com

I've had this article in mind for a while, as I have fiddling with Internet Explorer's crazy handling of attributes in order to patch Prototype's $$() utility.

Well, fiddling wasn't cutting the deal, so I ended up doing some large scale testing (basically running thousands of test using a sample HTML 4.01 document from W3C) to try to figure out what was going on.

element.foo === element.getAttribute('foo')

Obviously, that is a completely broken implementation, as getAttribute('foo') is supposed to return the attribute as set in the document, not the corresponding DOM element's attribute.

To exemplify:

<a href="http://tobielangel.com/index.html" onclick="alert('Back home!')">Home</a>
element.getAttribute('href');
// -> "http://tobielangel.com/index.html" in IE
// -> "/index.html" in well behaved browsers

If you read Internet Explorer's online documentation, you'll notice that it's implementation of getAttribute() is a bit particular, as it takes a second optional argument called an iFlag.

 powered by clipmarksblog it

No comments:

Your Ad Here