¿Marcar/desmarcar casilla con JavaScript (jQuery o Vanilla)?

¿Cómo se puede marcar/desmarcar una casilla de verificación utilizando JavaScript, jQuery o vanilla?

Solución

Javascript:

// Check
document.getElementById("checkbox").checked = true;

// Uncheck
document.getElementById("checkbox").checked = false;

jQuery (1.6+):

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

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

jQuery (1.5-):

// Check
$("#checkbox").attr("checked", true);

// Uncheck
$("#checkbox").attr("checked", false);
Comentarios (6)

para comprobarlo:

document.getElementById("id-of-checkbox").checked = true;

para desmarcarse:

document.getElementById("id-of-checkbox").checked = false;
Comentarios (1)

Podemos marcar una casilla de verificación de partículas como,

$('id of the checkbox')[0].checked = true

y desmarcar por ,

$('id of the checkbox')[0].checked = false
Comentarios (4)