Hello Knockout.JS
To start using Knockout.JS is very simple. It is nothing more than a couple of JavaScript lines of code and a special attribute added to the DOM
tags.
An example of an HTML page can be as follows:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Hello Knockout.JS</title> </head> <body> <span data-bind="text: message"></span> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script> <script type="text/JavaScript"> var viewModel = { message: "Hello Knockout.JS!" }; ko.applyBindings(viewModel); </script> </body> </html>
Note
We put the script
tags just before the closing body
tag for performance reasons, as stated in the best practices document of the Yahoo Developer Network...