Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple classes with knockout css binding

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

like image 671
Thomas Hopkins Avatar asked Dec 03 '22 19:12

Thomas Hopkins


2 Answers

Try this:

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

See documentation

like image 136
haim770 Avatar answered Dec 05 '22 09:12

haim770


you can also use a string like this:

<div class="animal" data-bind="css:{'mammal dog':true}"></div>
like image 39
Reza Avatar answered Dec 05 '22 07:12

Reza