Class binding in knockout js

One of the most useful binding in knockout, although all are important.
Bind one or more class and remove class(es).

We have taken an example of stock upside and down and based on values of it we will show class.

On above example, we used computed knockout observable which works same as normal observables but difference only that , it give return value(s) after processing on it.
What we have did that, if current stock value is below zero we will add stockDown class and if not add stockUp class. Another thing, on initialization stock value is 150000 but after that on line number 22 of code, we have changed it to negative.
Based on such condition class can be changed and added.

Leave a Reply