When I click a checkbox, why does checked attribute is not getting added?. You can see the code here
http://jsfiddle.net/FCrSg/
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
The HTML attribute
checked
means: checked by default, when the page loads. This won't change when the checkbox is clicked.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.What are you trying to do? Find out if its checked?
http://jsfiddle.net/petersendidit/FCrSg/1/
If you want to see it appear on the element displayed in the console, use the native
setAttribute()
method.Example: http://jsfiddle.net/FCrSg/2/
So it would look like this:
Then the console should give you:
Though you normally wouldn't need the attribute set like that. Typically the property is enough.