The “visible” and “hidden” bindings

These both act same as CSS hidden and visible. Used to show or hide part of HTML based on values passed to knockout binding.

BindValueOutput
hiddentruehide
hiddenfalseshow
visibletrueshow
visiblefalsehide

Let’s check code for same.

In above code, showMenu declared as knockout observable with initial value of true. Later it change value of showMenu to false and true again.
It is visible binding so true value show and if false it hides.

Now let’s look at hidden binding. It works opposite of visible. When showMenu is true it hides and when false then it will show.


Using functions and expressions to control element visibility

Same way you can use for hidden but remember it works opposite.

Additional Information on Parameters:

ValueConditionsKnockout output
FALSEIf boolean is false, numeric value is 0, null or undefinedyourElement.style.display to none
TRUEIf boolean is true, non-null object or arrayyourElement.style.display to visible

Leave a Reply