Reputation: 1943
I have two divs generated dynamically using knockoutbinding as follows:
<div id="simdivs" data-bind="text:$data.Name,visible:$data.Name !== undefined"></div>
I want to conditionally give a css styling as "margin-left:1px"
if the data.Name from the second div is "" (empty) else "margin-left:0px"
how do I achieve this using knockout js?
Upvotes: 1
Views: 191
Reputation: 806
Use the Style data-bind
<div id="simdivs" data-bind="style: {marginLeft: $data.Name === null ? '1px' : '0px'}></div>
Do note that it is written as marginLeft
instead of margin-left
Upvotes: 1