Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

465
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!