I have a question about style binding. Is it possible to generate all style binding text? So, ownership and value of parts together? For example:
function ViewModel() { this.fontSize = ko.observable(12); this.fontSizeCSS = ko.computed(function() { return "font-size: " + " " + this.fontSize() + "px"; }, this); }
A simple way is:
<div data-bind="style: { fontSize: fontSize() + 'px'}"> <p>Lorem ipsum</p> </div>
Is it possible to do it like this (I tried, this did not work):
<div data-bind="style: { fontSizeCSS() }"> <p>Lorem ipsum</p> </div>
If so, how? If not, why not? You can associate text with an html style element, but I was wondering if you can make this somewhat similar to what I suggest? Thanks!
Zsombi
source share