Skip to main content
grammar check and clarifications
Source Link
Spoike
  • 14.8k
  • 4
  • 45
  • 59

The scope to which elements knockout binds itself with is determined from the way you call ko.applyBindings.

By default It takes two parameters, an object to be used as the root view model and an element to "apply" the bindings on. The latter parameter is optional and usually tutorials and documentation leaves it out like this:

ko.applyBindings(viewModel);

ItBy default, without the second parameter, knockout will apply the bindings on the whole document. If you want to limit itthe bindings from one specific HTML element you can specify a html elementit as the second parameter to be used as a parent instead of the document. LikePretty much like this:

var parent = document.getElementById('someElementId');
// or if you are using jquery, use $('#someElementId')[0]

ko.applyBindings(viewModel, parent);

It is briefly described in this section of the knockout docs.

The scope to which elements knockout binds itself with determined from the way you call ko.applyBindings.

By default:

ko.applyBindings(viewModel);

It will apply the bindings on the whole document. If you want to limit it you can specify a html element to be used as a parent instead of the document. Like this:

var parent = document.getElementById('someElementId');
// or if you are using jquery, use $('#someElementId')[0]

ko.applyBindings(viewModel, parent);

It is briefly described in this section of the knockout docs.

The scope to which elements knockout binds itself with is determined from the way you call ko.applyBindings. It takes two parameters, an object to be used as the root view model and an element to "apply" the bindings on. The latter parameter is optional and usually tutorials and documentation leaves it out like this:

ko.applyBindings(viewModel);

By default, without the second parameter, knockout will apply the bindings on the whole document. If you want to limit the bindings from one specific HTML element you can specify it as the second parameter to be used as a parent instead of the document. Pretty much like this:

var parent = document.getElementById('someElementId');
// or if you are using jquery, use $('#someElementId')[0]

ko.applyBindings(viewModel, parent);

It is briefly described in this section of the knockout docs.

Source Link
Spoike
  • 14.8k
  • 4
  • 45
  • 59

The scope to which elements knockout binds itself with determined from the way you call ko.applyBindings.

By default:

ko.applyBindings(viewModel);

It will apply the bindings on the whole document. If you want to limit it you can specify a html element to be used as a parent instead of the document. Like this:

var parent = document.getElementById('someElementId');
// or if you are using jquery, use $('#someElementId')[0]

ko.applyBindings(viewModel, parent);

It is briefly described in this section of the knockout docs.