The visible binding switches the element's visibility between "" and "none" , so you need to create a custom binding that supports inline display:
Based on the visible source code (you can further expand this transfer in a file with a saved value as a parameter):
ko.bindingHandlers['visibleInline'] = { 'update': function (element, valueAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()); var isCurrentlyVisible = !(element.style.display == "none"); if (value && !isCurrentlyVisible) element.style.display = "inline"; else if ((!value) && isCurrentlyVisible) element.style.display = "none"; } };
And use in your html:
<h3 style='display: inline' data-bind='visibleInline: Total() > 3, text: Total'></h3>
JSFiddle demo.
Or as an alternative solution, you can use the syntax without a container and not put the binding on h3 and use if instead of visible :
<h3 style='display: inline'> </h3>
JSFiddle demo.
source share