I tried this one :
<div data-bind="attr: {class: itemSelected? 'selected' : 'unselected' }"></div>
But it does not work 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you have this:
Add a () after itemSelected to get the current value of the observable that you can use with the ternary operator:
<div data-bind="attr: { class: itemSelected() ? 'selected' : 'unselected' }"></div>http://jsfiddle.net/RK7Ty/
If you didn’t need to assign the unselected class for the non selected state you could do this instead:
http://jsfiddle.net/RK7Ty/1/