user6483684 user6483684 - 2 months ago 5x
jQuery Question

ko.js twice in a page

Is it possible to have two ko.js in a page? they have different class and id. If it's possible what code do I need to use to have them work together at the moment one of the coded are not working it is being over shadowed by the first one


As I see from your previous question you have 2 view models and you want to apply them to different elements in the HTML.

You can call the applyBindings method with a second parameter- the HTMl element on which you want to apply your view model.

 ko.applyBindings(viewModel1, $('.firstdiv').get(0))
 ko.applyBindings(viewModel2, $('.seconddiv').get(0))

If the two views/HTML elements are nested one in other you have to use a skipBinding.