Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:07:31+00:00 2026-06-16T03:07:31+00:00

In knockout.js we have a basic example with the most basic text binding: Today’s

  • 0

In knockout.js we have a basic example with the most basic text binding:

Today's message is: <span data-bind="text: myMessage"></span>

<script type="text/javascript">
    var viewModel = {
        myMessage: ko.observable() // Initially blank
    };
    viewModel.myMessage("Hello, world!"); // Text appears
</script>

This is straight from tutorial http://knockoutjs.com/documentation/text-binding.html
What if I want to have a variable that defines the actual binding property. That could look something like this:

Today's message is: <span data-bind="myBinding: myMessage"></span>

<script type="text/javascript">
    var viewModel = {
        myMessage: ko.observable(), // Initially blank
        myBinding: ko.observable(), // Initially blank
    };
    viewModel.myMessage("text");
    viewModel.myMessage("Hello, world!"); // Text appears
</script>

Above code is obviously wrong, but what would the correct case be?

I was looking into some stuff like ko.applyBindingsToNode ( Can I dynamically bind element inside custom binding? ) but the Google FU is totally failing me this time, because most of the thing I find is applying bindings to dynamically built elements and not apllying dynamic binding types dynamically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:07:32+00:00Added an answer on June 16, 2026 at 3:07 am

    You cannot use an observable as a custom binding type. Observable’s are for storing data.

    You can get the functionality you want by using either a Custom Binding or a Computed Observables. Personally, if this is something special that you need one time, then use a Computed Observable. Otherwise, use a custom binding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a knockout template like this: <script type=text/html id=list> <ul data-bind=foreach: items> <li
In knockout.js I have a very standard field that looks like this: <label data-bind=text:
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I have this basic knockout script set up (still learning) $.getJSON(clientUrl + /list/ +
Attempting the most basic example of Knockout.js possible on their documentation page: http://knockoutjs.com/documentation/observables.html Looks
Suppose I have knockout.js template like this: <script type=text/html id=mytemplate> <label for=inputId>Label for input</label>
I have 3 levels of data to manage in Knockout, but only the first
This is a real simple example, I have a basic JavaScript object with an
I have a knockout.js ViewModel with an observable array: function ItemsViewModel() { this.data =
I have a basic table set up using knockout, but I was wondering if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.