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 8761107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:12:34+00:00 2026-06-13T15:12:34+00:00

I am new to Knockoutjs, starting with http://learn.knockoutjs.com/ tutorial but the same when i

  • 0

I am new to Knockoutjs, starting with http://learn.knockoutjs.com/ tutorial but the same when i am trying in local it is not working.

Do i need to write model and view in separate file or same, My question is how to run first knockout program.

<!DOCTYPE HTML>
<html>
    <head>
    <title></title>
        <script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/knockout/2.1.0/knockout-min.js'></script>
        <script type="text/javascript">
                    // Here's my data model
            var ViewModel = function(first, last) {
                this.firstName = ko.observable(first);
                this.lastName = ko.observable(last);
                this.fullName = ko.computed(function() {
                    // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
                    return this.firstName() + " " + this.lastName();
                }, this);
            };

            ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work​​​​​​​​​​​​​​​​​​
            </script>
    </head>
    <body>
            <div class='liveExample'>   
    <p>First name: <input data-bind='value: firstName' /></p> 
    <p>Last name: <input data-bind='value: lastName' /></p> 
    <h2>Hello, <span data-bind='text: fullName'> </span></h2>  
</div>​
    </body>
</html>
  • 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-13T15:12:35+00:00Added an answer on June 13, 2026 at 3:12 pm

    You should put ko.applyBindings to the end of page. Here is a quote from official documentation:

    To activate Knockout, add the following line to a block:

    ko.applyBindings(myViewModel);

    You can either put the script block at the bottom of your HTML
    document, or you can put it at the top and wrap the contents in a
    DOM-ready handler such as jQuery’s $ function.

    So code should look as follow:

    <!DOCTYPE HTML>
    <html>
        <head>
        <title></title>
            <script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/knockout/2.1.0/knockout-min.js'></script>
        </head>
        <body>
           <div class='liveExample'>   
               <p>First name: <input data-bind='value: firstName' /></p> 
               <p>Last name: <input data-bind='value: lastName' /></p> 
               <h2>Hello, <span data-bind='text: fullName'> </span></h2>  
           </div>​
           <script type="text/javascript">
                // Here's my data model
                var ViewModel = function(first, last) {
                    this.firstName = ko.observable(first);
                    this.lastName = ko.observable(last);
                    this.fullName = ko.computed(function() {
                        // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
                        return this.firstName() + " " + this.lastName();
                    }, this);
                };
    
                ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work​​​​​​​​​​​​​​​​​​
           </script>
        </body>
    </html>
    

    Here is working fiddle: http://jsfiddle.net/vyshniakov/s2LSE/

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

Sidebar

Related Questions

Really starting to enjoy KnockoutJs (http://knockoutjs.com). Most of my web apps are ajax driven.
I'm new to KnockoutJS but am liking it so far. What I'm trying to
I'm new to KnockoutJs and am trying to understand the error Unable to parse
With the new KnockoutJS native DOM-enabled templating life's gonna be easy. But sometimes pages
I'm new to KnockoutJs and I'm trying to use it with ASP.net webforms in
I'm new to KnockoutJS , and I'm stuck trying to add additional properties and
I am reading this very interesting article about knockoutJs ( http://wildermuth.com/2011/11/20/Using_MVVM_on_the_Web_with_KnockoutJS ) And I
I am coding a dynamic query editor with knockoutjs, but ko.toJSON is not outputting
This seems possible as http://www.knockoutjs.com appears to be doing it. I haven't been able
I am starting a new project, and keen to make use of the KnockoutJS

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.