-
-
Save devdays/35168ac8bae57f93db16 to your computer and use it in GitHub Desktop.
Object JavaScript - Show Hide using Knockout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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