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

  • SEARCH
  • Home
  • 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 7782111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:26:23+00:00 2026-06-01T19:26:23+00:00

I’ve been using knockout for a while, but in writing up some code examples

  • 0

I’ve been using knockout for a while, but in writing up some code examples this one has me stumped. The code works exactly as I’m expecting, where the click button toggles the visible, but I’m still getting an error:

JsFiddle: http://jsfiddle.net/JasonMore/hCdF8/1/

Uncaught Error: Unable to parse bindings.
Message: ReferenceError: answerClick is not defined;
Bindings value: click: answerClick

from

<ul data-bind="foreach: answers">
    <li>
        <a class="hiddenButton" href="#" data-bind="click: answerClick" />
        <div class="answerNumber" data-bind="visible: showAnswerNumber">
            <h2 data-bind="text: answerNumber" />
        </div>
        <div class="answer" data-bind="visible: showAnswerText">
            <p data-bind="text:text" />
            <p data-bind="text: points" />
        </div>
    </li>
</ul>

<script type="text/javascript">

    var answerViewModel = function () {
        var self = this;

        //clicks
        self.answerClick = function () {
            self.showAnswerNumber(!self.showAnswerNumber());
        };

        //observables
        self.answerNumber = ko.observable();
        self.text = ko.observable();
        self.points = ko.observable();
        self.showAnswerNumber = ko.observable(true);

        //computed
        self.showAnswerText = ko.computed(function () {
            return !self.showAnswerNumber();
        });
    };

    var roundViewModel = function () {
        var self = this;
        self.answers = ko.observableArray();
    };

    var answer1 = new answerViewModel();
    answer1.text = "foo answer";
    answer1.answerNumber = 1;
    answer1.points = 50;

    var vm = new roundViewModel();
    vm.answers.push(answer1);

    ko.applyBindings(vm);

</script>
  • 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-01T19:26:25+00:00Added an answer on June 1, 2026 at 7:26 pm

    Because you are closing your anchor tag: <a />, it is getting rendered in a strange way where an extra anchor tag is outside of the foreach and not in a context where answerClick is a valid function.

    I am not sure what content that you want to use for your link, but you need to have an opening and closing tag like:

    <a class="hiddenButton" href="#" data-bind="click: answerClick">link</a>

    Not sure if you intended to wrap the content in that link, but that is where your issue lies.

    Sample: http://jsfiddle.net/rniemeyer/hCdF8/2/

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.