24

I have some html like the following:

<div class="control-group">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

However, ifnot: $data.DealCodeIsValid, I need to render the following:

<div class="control-group error">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

Note the additional class "error" in the div. Is there a way to do that with knockoutjs?

1 Answer 1

36

Something like

<div data-bind="css: {'control-group': true, error: (!$data.DealCodeIsValid)}">

Check here for more info

Sign up to request clarification or add additional context in comments.

2 Comments

I found that about 10 minutes after posting this. Thanks @jon.
@devlife thankfully jon posted this 8 minutes after u asked, so u saved 2 minutes. :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.