How to change checkbox checked value in Knockout.js?


stereotaxic

I want to change the value of the checkbox via jQuery, but the knockout binding doesn't work

var viewModel = {
    myValue: ko.observable(true)
};

ko.applyBindings(viewModel);

$(':checkbox').prop({checked: false}).change();

http://jsfiddle.net/stereodenis/n7zxvu01/3/

TSV

It's described in the Knockout.js documentation: checked binding .

<p>Send me spam: <input type="checkbox" data-bind="checked: wantsSpam" /></p>

<script type="text/javascript">
var viewModel = {
    wantsSpam: ko.observable(true) // Initially checked
};

// ... then later ...
viewModel.wantsSpam(false); // The checkbox becomes unchecked
</script>

Related


Knockout JS checkbox checked binding

gth685f In knockout js, I am trying to perform a foreach on an array of data to display checkboxes. The problem I'm having is that the selected databinding doesn't seem to work until I interact with one of the boxes. For example, below I will generate 5 textbo

Knockout JS checkbox checked binding

gth685f In knockout js, I am trying to perform a foreach on an array of data to display checkboxes. The problem I'm having is that the selected databinding doesn't seem to work until I interact with one of the boxes. For example, below I will generate 5 textbo

How can I change the value of the checkbox if checked?

or I want to change the value of checkboxes when I select them from 0-1 This is what I tried HTML <input type="checkbox" name="Semi Annual" id="1" value="0"> Semi Annual <br> <input type="checkbox" name="Quaterly" id="2" value="0">

How can I change the value of the checkbox if checked?

or I want to change the value of checkboxes when I select them from 0-1 This is what I tried HTML <input type="checkbox" name="Semi Annual" id="1" value="0"> Semi Annual <br> <input type="checkbox" name="Quaterly" id="2" value="0">

Knockout.js checkbox checked and click event

David Reid We are trying to implement checkboxes and lists with the following functionality: Clicking the checkbox will clear the array (if there are items in it), or add a new item (if there are none). When the delete button is clicked, an item is removed fro

How can I change the boolean value if the checkbox is checked?

gmark11 I want to change a boolean value in a component file with a simple checkbox. It should remain false if not checked, otherwise it should be true. Element: export class UsersComponent { public Personal: boolean = false; } HTML: <label> <input type

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change textcolor with CheckBox checked

Theinlwin I want to check Inputype . The text color is red . <div class="checkbox"><label><input type="checkbox"> Sedan <span>(10)</span></label></div> <div class="checkbox"><label><input type="checkbox"> Sedan <span>(10)</span></label></div> demo Mohit kum

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im