Alexander Karlstad. Blogger hovedsakelig om Linux og sånt.

Internet Explorer 6's DOM label.htmlFor handling

Lately I've been working on making a AJAX-based poll which also sets/checks whether a cookie exists for the current one. Of course, something does not and will not work in IE6.
This time it's the for-attribute in label-elements. When creating a DOM-node with


, it will so absolutely NOT render this 😒 I've tried "elem.htmlFor" (which is correct and works in all other browsers, even IE7), "elem.for" (which, of course, does not work in either), "elem['for']" and "elem['htmlFor']".
First, I thought this doesn't work when doing it the DOM-way, but when I later on tried to add the attribute by looping over all the label-elements I could find, it did not work either. God damn hippie browser. 🐒
The only way I got this thing working, was by inserting the HTML in the "good old" cursed way, by modifying the innerHTML-property of the node.

elem.innerHTML = '<label for="foobar">Foo + bar</label>';

Thank God it's only tuesday. Anyone else had any similar experiences? Feel free to comment 🙂

Edit: A nifty hack made IE6 do it's job. By adding a function that checks the radiobutton and binding this to the "onclick" on the label does the job.

Skrevet av Alexander Karlstad

26. august 2008 klokken 20.05

Skriv en kommentar

Optimization WordPress Plugins & Solutions by W3 EDGE