Reputation: 44550
How can I use knockout if my html is already rendered. I'd like to apply binding on checkbox: when checkbox is checked I want my textarea be enabled and vice versa.
How can I achieve this?
Upvotes: 0
Views: 135
Reputation: 155
I don't understand
How can I use knockout if my html is already rendered
but if your question is How can i enabled a textbox according to checkbox state you can try this :
<div><input type="checkbox" data-bind="checked: isTextBoxEnabled"/>Enable textbox</div>
<div><input type="input" data-bind="enable: isTextBoxEnabled"/></div>
var ViewModel = function() {
var self = this;
self.isTextBoxEnabled = ko.observable(true);
};
ko.applyBindings(new ViewModel());
Upvotes: 1
Reputation: 17554
You shouldnt do it, but it works.
Just add the data-bind attribute to the elements. Lists of checkboxes etc wont work though
Upvotes: 1