1

I'm trying to add a binding in the <html> element of the site and it doesn't seem to have any effect.

Is there any restriction applying bindings in elements outside the body element?

<html xmlns="http://www.w3.org/1999/xhtml" data-bind="css: {'visible-menu' : $root.panels.visibleMenu }">
Alvaro
  • 40,778
  • 30
  • 164
  • 336

1 Answers1

3

applyBindings defaults to using <body> if you don't pass a root node:

rootNode = rootNode || window.document.body; // Make "rootNode" parameter optional

If you pass the <html> node, it should work as expected. One way to do this, if you're using jQuery, is to use the :root selector:

ko.applyBindings(viewModel, $(':root').get(0));

Or by tag name:

ko.applyBindings(viewModel, document.getElementsByTagName('html')[0]);
James Thorpe
  • 31,411
  • 5
  • 72
  • 93