Reputation: 15706
I need to dynamically generate radio or checkbox by jQuery.
I use the following code:
var type = "radio"; // maybe checkbox
$('<input type="'+ type +'">').attr({
name: "ename", value: "1"
})
However, the radio generated cannot be selected in IE6(other browsers are fine). What should I do?
marcc's answer solves my problem.
Upvotes: 0
Views: 438
Reputation: 12399
It's the way IE6 works, you cannot set the Name attribute on elements created dynamically.
Set the Name attribute before the attr.
$('<input type="' + type + '" name="ename">').attr('value', '1');
or even
$('<input type="' + type + '" name="ename" value="1">');
Upvotes: 4