Androme
Androme

Reputation: 2449

Knockout binding in style

Is is possible to bind in side a style with knockout? See the example:

<div style="background: url('!!INSERT IMAGE LINK HERE!!!') no-repeat; padding-left: 25px">

I know i can make a string in my view model that contains it all, but i would like to keep the css seperated from my view model.

Upvotes: 3

Views: 360

Answers (1)

magritte
magritte

Reputation: 7636

You could use a style binding to set the background depending on a property on the view model, see http://knockoutjs.com/documentation/style-binding.html

Having said that I generally think it's better separation if you use the css binding http://knockoutjs.com/documentation/css-binding.html and define a css class to represent the state.

Upvotes: 1

Related Questions