How can I change a checkbox for a radio button using jQuery?
var checkbox = $("#myCheckbox");
checkbox.replaceWith('<input type="radio" name="'+checkbox.attr('name')+'" value="'+checkbox.attr('value')+'" />');
Or with jQuery 1.4
var checkbox = $("#myCheckbox");
$("<input>",{
type:'radio',
name: checkbox.attr('name'),
value: checkbox.attr('value')
}).replace(checkbox);
You change change the type attribute because it causes problems in IE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With