You can use the attr binding to set the class (as suggested by @david.s) but when I have this type of logic I tend to put it in a custom bindingHandler.
I would make the viewModel expose some state information that would determine (in this case) border color but is not directly tied to a class:
this.state = ko.observable("complete"); //complete, pending, or cancelled (for example)
I would then use a binding handler to map this onto classes
ko.bindingHandlers.stateStyle = {
update: function(element, valueAccessor) {
var state = ko.utils.unwrapObservable(valueAccessor());
if (state === "completed") {
$(element).addClass("hasGreenBorder"); //again, just an example
}
else if (state === "pending") {
//etc
}
}
}
Then I would use the new binding on the element
<div data-bind="stateStyle: state"></div>
This approach means that the view model is not directly referencing css classes (which feels wrong to me) and that the logic for state1 => green border is not defined in an inline binding in the view.