JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script>
<div id="output-div">
<span><b>My name: </b></span>
<span data-bind="text: name"></span>
<br />
<span><b>My age: </b></span>
<span data-bind="text: age"></span>
</div>
CSS
body
{
font-family: Arial;
}
JavaScript
// A simple viewmodel using Knockout JS
// Our viewmodel
function viewmodel() {
self = this;
this.name = "David Anderson";
this.age = 50;
}
// Runs at document load
$(document).ready(function(){
// Create an instance of the viewmodel
var myViewmodel = new viewmodel();
// Bind the instance to the view
ko.applyBindings(myViewmodel);
// Change the model values later
myViewmodel.name = "Steven Hackett";
myViewmodel.age = 57;
});