DEV Community

Avnish Jayaswal
Avnish Jayaswal

Posted on

Setting “checked” for a checkbox with jQuery

You can check or uncheck a checkbox element or a radio button using the .prop() method:


// Check #x
$( "#x" ).prop( "checked", true );

// Uncheck #x
$( "#x" ).prop( "checked", false );

Enter fullscreen mode Exit fullscreen mode

f you’re working with just one element, you can always just access the underlying HTMLInputElement and modify its .checked property


$('.x')[0].checked = true;
$('.x')[0].checked = false;

Enter fullscreen mode Exit fullscreen mode

jQuery 1.5.x and below

$('.x').attr('checked', true);
$('.x').attr('checked', false);

Enter fullscreen mode Exit fullscreen mode

Read More : Setting “checked” for a checkbox with jQuery

Top comments (0)