Tags: , , | Posted by AlexanderZeitler on 12/26/2011 8:16 PM | Comments (0)

When applying bindings in knockoutjs explicitely to a specific DOM element, you may get this error:

Uncaught Error: ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node

Your HTML might look like this:

...and your Javascript like this:

Whats wrong with it? Let's try document.getElementById instead:

Now everything works as expected:

correct list

So what’s wrong with the jQuery way of selecting the DOM element?

When using var menu = $("#menu") we don’t get a DOM object but a jQuery object instead.

To get the correct DOM element, we have to use one of the ladder two of the following (first one is for understanding purposes only):

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Comments are closed