Checkbox checkedPropiedad
Objeto Checkbox
Definición y uso
La propiedad checked establece o devuelve si el checkbox debe estar marcado.
Sintaxis
Establecer la propiedad checked:
checkboxObject.checked=true|false
Devolver la propiedad checked:
checkboxObject.checked
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad checked
Ejemplo
Ejemplo
El siguiente ejemplo establece el estado del checkbox:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function check(){
document.getElementById("check1").checked=true
}
function uncheck(){
document.getElementById("check1").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="check1">¿Te gusta el verano?
</form>
<button onclick="check()">Marcar casilla</button>
<button onclick="uncheck()">Desmarcar casilla</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function check(){
document.getElementById("check1").checked=true
}
function uncheck(){
document.getElementById("check1").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="check1">¿Te gusta el verano?
</form>
<button onclick="check()">Marcar casilla</button>
<button onclick="uncheck()">Desmarcar casilla</button>
</body>
</html>
Pruébalo »
Más ejemplos
Objeto Checkbox Otras extensiones