Kategorier
Utvikling

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

document.createElement('label')

, 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.

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *

Dette nettstedet bruker Akismet for å redusere spam. Lær om hvordan dine kommentar-data prosesseres.