How to add a dynamic class in knockoutjs?

You should use css binding instead of attr for this. Read more about it in the documentation: http://knockoutjs.com/documentation/css-binding.html.

You code will look something like this:

<span class="cls1 cls2" data-bind="text: title, css: myClass" ></span>

Here is working fiddle: http://jsfiddle.net/vyshniakov/gKaRF/

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)