Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a checkbox for a radio button using jQuery?

Tags:

html

jquery

How can I change a checkbox for a radio button using jQuery?

like image 545
Jedi Master Spooky Avatar asked Dec 04 '22 13:12

Jedi Master Spooky


1 Answers

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.

like image 98
PetersenDidIt Avatar answered Mar 23 '23 07:03

PetersenDidIt