Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  2] [ 2]  / answers: 1 / hits: 41404  / 15 Years ago, tue, september 1, 2009, 12:00:00

According to SitePoint (and my own experiments), the IE implementation of setAttribute() is buggy and unreliable.



Also according to SitePoint, the name attribute is read-only.



Is there another way I can set the name attributes on elements? I need this for use with radio buttons. If possible, I'd like a solution without jQuery, as I'm currently not using the library.



Thanks in advance!


More From » dom

 Answers
29

Sitepoint liesis talking about a different usage of ‘name’ (see Anthony's comment). It's not read-only, it's just there's a long-standing IE bug (up to v7) where setting ‘name’ on form fields is only partially effective. Radio buttons in particular don't accept it properly.



The Microsoft-endorsed solution, as detailed here is to use a horrific misfeature of IE's version of the createElement call to set attributes at the same time:



var radio= document.createElement('<input type=radio name=test value=a />');


Probably a better way would simply be to use good old innerHTML, eg.:



var div= document.createElement('div');
div.innerHTML= '<input type=radio name=test value=a />';
var radio= div.firstChild;

[#98786] Thursday, August 27, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucillemariselal

Total Points: 108
Total Questions: 97
Total Answers: 119

Location: Thailand
Member since Thu, May 6, 2021
3 Years ago
;