Reputation: 1099
I have a button should have "Start" as value then if the button clicked should change to "Pause"
> <script> let isOn = false;
fucntion startPause() {
if (!isOn){
// do something
isOn = true; }else{
// do something else
isOn = false; }
// ... </script>
<button data-bind ="click: startPause" ></button>
Upvotes: 0
Views: 1044
Reputation: 3634
Here is an example : https://jsfiddle.net/kyr6w2x3/70/
HTML:
<button type="button" class="btn btn-default" data-bind="text:buttonText,click:startPause">
JS:
function AppViewModel() {
var self = this;
self.buttonText = ko.observable('Start');
self.startPause = function (){
// here you can have your own logic to toggle the value
self.buttonText(self.buttonText().toUpperCase() === 'START' ? 'Pause' : 'Start');
}
}
ko.applyBindings(new AppViewModel());
Upvotes: 1
Reputation: 3
Use the text binding and use an observable to change it's value on the model.
ref: The "text" binding
Upvotes: 0