4

I need to add two classes to an element using the css binding.

For example:

<div class="animal" data-bind="css: mammal, dog"></div>

However this only adds the first class, "mammal".

Please could you tell me what I'm doing wrong. Thanks

2
  • see: stackoverflow.com/questions/17918300/… Commented Aug 11, 2014 at 8:45
  • 1
    data-bind="css: {mammal:true, dog:true}" or data-bind="css: mammal, css: dog" should both work. Commented Aug 11, 2014 at 9:50

3 Answers 3

10

Try this:

<div class="animal" data-bind="css: {mammal:true, dog:true}"></div>

See documentation

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

Comments

6

you can also use a string like this:

<div class="animal" data-bind="css:{'mammal dog':true}"></div>

Comments

1

you do not need to have a comma (,). just write with a space like below:

 <div data-bind="css:{'class1 class2 class3':true}"></div>

Comments

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.