Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Knockout JS - Update view visibility when observable changes value

So I was trying to update an span tag visibility when a value changes, but noticed that using if: and directly using the compare operator there doesn't work when the value changes. For example:

<span data-bind="if: firstName === 'Bert'">Hello</span>

So if we have initially something else in the firstName observable it will not be visible. Theorically if we change the value to Bert (maybe using a text input) or a function that changes the value it should show the Hello span, but it isn't working.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To update the HTML component using the if statement, we should use a function in the JS and call the function like below.

In the JS (inside the view model):

this.showSpan = function() {
    return this.firstName() === 'Bert'
}

And in the HTML:

<span data-bind="if: showSpan()">Hello</span>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!