1

According to the "visible" binding documentation, Knockout uses display: none to hide elements if the the value of visible evaluates to false. How can I make it use visibility: hidden instead? visibility: hidden has the advantage (in this case) of still making the element take up space on the page.

1
  • You can use a style or css binding
    – adiga
    Jan 12, 2018 at 13:48

1 Answer 1

5

You should use plain css style or classes, check the official knockout.js css binding or knockout.js style binding documentations.

Style binding example :

<div data-bind="style: { visibility: isVisible()  ? 'visible' : 'hidden' }">
    Profit Information
</div>

<script type="text/javascript">
    var viewModel = {
        isVisible: ko.observable(true) // visible
    };
    viewModel.isVisible(false); // hidden
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.