For the life of me I cant set my CheckBox to checked at page load.
I have tried adding value=\"true\"
and Checked=\"checked\"
after id and still noth
The attribute checked="checked"
does work and the shorthand notation is just checked
.
<div class="onoffswitch-container">
<span class="onoffswitch-title">Open Inline</span>
<span class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked="checked"/>
<label class="onoffswitch-label" for="inline">
<span class="onoffswitch-inner" data-swchoff-text="OFF" data-swchon-text="ON"></span>
<span class="onoffswitch-switch"></span>
</label>
</span>
</div>
added "true" parameter below, just try it before, and it works for me
<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked="true">
I tried all above solutions and nothing worked. It did give me some terminology to continue my research. What I ended up doing was going to the bottom of the code and added $('#inline').prop('checked', true);
This solved my problem.
just write "checked" and it works
<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked>
You're looking for the checked
content attribute. Here's the relevant snippet from the official documentation: (Living Standard):
The checked content attribute is a boolean attribute that gives the default checkedness of the input element. When the checked content attribute is added, if the control does not have dirty checkedness, the user agent must set the checkedness of the element to true; when the checked content attribute is removed, if the control does not have dirty checkedness, the user agent must set the checkedness of the element to false.
Note the docs have links to definition of relevant terms.
If it seems too technical, you can always go to MDN page on checked. MDN contributors have put up considerable effort into "translating" HTML Standard into more readable/understandable form (often times with examples), especially useful to people without a solid foundation on web related terminology and concepts.
Note: You'll also find the direct answer to your question on MDN.