JSFiddle - React, Tailwind, and code Playground

by fergal_doyle

HTML

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<button type="button" id="get">Get</button>
<button type="button" id="set">Set</button>
<div>
    <input type="checkbox" value="cherry" data-bind="checked: ch1" />Cherry</div>
<div>
    <input type="checkbox" value="almond" data-bind="checked: ch2" />Almond</div>
<div>
    <input type="checkbox" value="msg" data-bind="checked: ch3" />Monosodium Glutamate</div>

JavaScript

var viewModel = {
    wantsSpam: ko.observable(true),
    ch1: ko.observable("fooooooooooooo"),
    ch2: ko.observable(""),
    ch3: ko.observable("")
};

// ... then later ...
//   viewModel.spamFlavors.push("msg"); // Now additionally checks the Monosodium Glutamate checkbox

ko.applyBindings(viewModel);



$("#get").click(function () {
    console.log(viewModel.ch1());
    console.log(viewModel.ch2());
    console.log(viewModel.ch3());
});