Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

466
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda