Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 16, 2014 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/35168ac8bae57f93db16 to your computer and use it in GitHub Desktop.
Save devdays/35168ac8bae57f93db16 to your computer and use it in GitHub Desktop.
Object JavaScript - Show Hide using Knockout
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show Hide</title>
</head>
<body>
<div data-bind="visible: onoff">Show Me</div>
<button data-bind="click: showMe, disable: onoff">Show Text</button>
<button data-bind="click: hideMe, enable: onoff">Hide Text</button>
<script src="Scripts/knockout-2.2.1.debug.js"></script>
<script>
var viewModel = function () {
this.onoff = ko.observable(true); // onoff is intially set to true
hideMe = function() {
this.onoff(false);
};
showMe = function () {
this.onoff(true);
};
}
ko.applyBindings(new viewModel());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment