SteveSanderson/knockout — Issue #233: "attr" binding throws 'unable to parse' if (subset) of attributes not quoted in binding
Author: DazWilkin
Created: 2011-12-16 05:37:15+00:00
State: open

I understand, from the documentation that the attr binding does not require the DOM attribute to be quoted. Unfortunately, for some subset of attributes, this throws an "unable to parse" error in Safari 5.0.5. It works as described in the other browsers.

http://knockoutjs.com/documentation/attr-binding.html

Error: Unable to parse bindings.
Message: SyntaxError: Parse error;
Bindings value: text: $data, attr: { class: $data }

Here's an example. The class attribute is not quoted. This works as defined in Chrome, IE and Firefox. However, in Safari it will throw the error. Change it to { 'class': $data } and it will work. It seems to be inconsistent in Safari. I tried using href and was able to use this without problems without quotes in Safari.

data-bind="text: $data, attr: { class: $data }"

Quoting the attributes appears to work correctly across browsers and may perhaps be the guidance.

Here's the fiddle:
http://jsfiddle.net/DazWilkin/SMPH9/1/