Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

467
Vistas
jquery/javascript input checkbox checked attribute (readonly not working)

Why is the checked attribute not visible in the DOM?

In the onchange input.val() is always on, but the checked attribute is changing??

input.change(_=> {
    console.log('val:', input.val(), ', checked:', input.prop('checked'));
});

console

val: on , checked: true
val: on , checked: false
val: on , checked: true
val: on , checked: false

readonly not working

If the input checkbox is readonly I can still change the value and when clicking the checkbox gives the same output in console

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The value of a radio or checkbox element doesn't change (unless you do it programmatically, but we're talking about simple user interaction with the form here).

When you check the radio/checkbox only the checked property changes. It's this property which should determine what action you take when your user interacts with the form.

Why is the checked attribute not visible in the DOM?

This is because it's the checked property of the Element object which is being updated, not the checked attribute. If you want to update the DOM change prop() to attr() in you JS code, but note that this is slower and serves no useful purpose in this case.

There is a very good answer here which goes in to detail on the difference between properties and attributes in JavaScript, which may help to clear up any confusion.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda