JSFiddle - React, Tailwind, and code Playground
by sifriday
HTML
<input id="x" data-bind="value: A" />
JavaScript
// Create a view-model
vm = {
A: ko.observable("a")
}
// Apply bindings; the input should now show 'a'
ko.applyBindings(vm);
// Set a timeout of 2 seconds.
window.setTimeout(function() {
// Change the value of the input outside of KO
document.getElementById("x").value = "b";
// Trigger change, to update the VM
var el = document.getElementById("x");
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
el.dispatchEvent(evt);
// Echo the value of the vm.A to the console; it should be 'b'
console.log(vm.A());
}, 2000);