Knockout JS – CSS Binding with dash in class name

Just put it in quotes:

<p data-bind="text: property, css: { 'with-dash': property().length > 0 }"></p>

Here’s an updated fiddle.

As a side note, you don’t need the > 0 since a length of 0 will evaluate to false, and any other length will evaluate to true:

<p data-bind="text: property, css: { 'with-dash': property().length }"></p>

Leave a Comment

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