The “attr” binding in knockout Js

This binding provides generic ways set values on DOM elements.
href of a tag, src of img, title of element, also can bind custom attribute but little different approach.

We binds title , href and target to <a/> tag.

Now let’s check on custom attributes binding such as data-custom or data-something.

We can not bind custom attributes not same we do with native attributes.
Below code does not work with custom attributes. Why?

Because data-custom or data-something is not legal identifier for javascript.

Solution is simple , just wrap identifier name in quotes just as below.

Leave a Reply