I am fairly new to Knockout and can't get my head around this problem.
The HTML is:
<span data-bind="text: greetings" />
<input data-bind="value: firstname" />
<input data-bind="value: lastname" />
<span data-bind="text: greetings">Default 2</span>
and the relevant JS is
<script type="text/javascript">
$(document).ready(function () {
var dv = document.getElementById('divMain');
ko.applyBindings(new Vm());
});
function Vm() {
this.greetings = ko.observable("hello world");
this.firstname = ko.observable("firstname");
this.lastname = ko.observable("lastname");
};
</script>
(jsfiddle)
The problem is that controls are not getting bound after the first span tag (greetings).
But if I enclose the span tag inside some div
then binding works for every control.
Is this behavior common? Why controls beyond first span wouldn't bind?.
Cheers,