Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why clicking on checkbox does not add the attribute checked='checked' [closed]

When I click a checkbox, why does checked attribute is not getting added?. You can see the code here http://jsfiddle.net/FCrSg/

like image 268
felix Avatar asked Sep 06 '25 12:09

felix


1 Answers

The HTML attribute checked means: checked by default, when the page loads. This won't change when the checkbox is clicked.

<input type="checkbox" checked="checked"> <!-- The HTML attribute -->

The DOM property checked is actually the current state of the checkbox and is either true/false. This will change when the checkbox is clicked, but isn't visible when you inspect the HTML.

$('input:check')[0].checked == true;
// Whether or not the checkbox is currently checked
like image 95
David Tang Avatar answered Sep 09 '25 20:09

David Tang