I want to set title attribute of span dynamically. I have tried below:
<span id="aPublic" class="pointer"
data-bind="attr:{title: {'mark private': isPublic, 'mark public': !isPublic()}}">
</span>
But it gives me [object Object].
You cannot do this in such way. Create computed value in your view model that will return needed title depends on isPublic property:
self.title = ko.computed(function(){
return self.isPublic() ? 'mark private' : 'mark public';
});
Or you can do this inside data-bind attribute but it is not considered the best of solutions:
<span id="aPublic" class="pointer"
data-bind="attr:{title: isPublic() ? 'mark private': 'mark public'}">
</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With