SteveSanderson/knockout — Issue #375: (jQuery template foreach) + (spaces around = in data-bind attribute) = exception
Author: mwcz
Created: 2012-03-09 04:15:00+00:00
State: open

The HTML5 spec allows for any number of spaces between an attribute name and the equals sign, and between the equals sign and the attribute value. Such as:

```xml

```
[HTML5 Source](http://dev.w3.org/html5/spec/Overview.html#attributes-0) (I can't find an explicit reference in the HTML 4.01 spec, but I haven't ever met a browser that didn't like spaces.)

I ran into an issue where I had an element with data-bind inside a template. Here is the exact template, from my ColorPal project:

```xml

```
Note the spaces on either side of the equals sign. This resulted in:

Uncaught Error: Unable to parse bindings.
Message: ReferenceError: hex is not defined;
Bindings value: style: { backgroundColor: hex }

Only the data-bind attribute inside the template was problematic. `hex` *is* defined, and the exception goes away when I remove the spaces, like so:

data-bind="style: { backgroundColor: hex }"

I have a fix to the data-bind regex (memoizeDataBindingAttributeSyntaxRegex) and will submit a pull request right away. I just wish I knew what the strange interplay is between jQuery.tmpl and Knockout.