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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:15:47+00:00 2026-06-04T00:15:47+00:00

In this example I want to use knockout.js to allow the Expand link to

  • 0

In this example I want to use knockout.js to allow the “Expand” link to be clicked and have its text changed to “Collapse”. I also want to set the make the jobDetails section visible. This is a very general question of how to get knockout.js to specifically modify the DOM of the “current” item in a list using a click handler.

<script type="text/html" id="job-template">
    <div class="jobContainer">
        <label data-bind="text: JobTitle"></label> 
        <label data-bind="text: CompanyName"></label>
        <div class="jobDetails">
            <label data-bind="text: City"></label>
            <label data-bind="text: State"></label>
        </di>
    <div>
        <a class="expand" href="#" data-bind="click: ???">Expand</a>        
    </div>
    </div>    
</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-04T00:15:49+00:00Added an answer on June 4, 2026 at 12:15 am

    This is very straight forward with KO. Here’s a simple way to do it. FYI I had to fix your markup slightly.

    <div>
        <div class="jobContainer">
            <label data-bind="text: JobTitle"></label>
            <label data-bind="text: CompanyName"></label>
            <div class="jobDetails" data-bind="visible: expanded">
                <label data-bind="text: City"></label>
                <label data-bind="text: State"></label>
            </div>
        <div>
        <a class="expand" href="#" data-bind="click: toggle, text: linkLabel">Expand</a>        
    </div>   
    
    
    var viewModel = function() {
        this.JobTitle = ko.observable("some job");
        this.CompanyName = ko.observable("some company");
        this.City = ko.observable("some city");
        this.State = ko.observable("some state");
    
        this.someValue = ko.observable().extend({ defaultIfNull: "some default" });
    
        this.expanded = ko.observable(false);
    
        this.linkLabel = ko.computed(function () {
            return this.expanded() ? "collapse" : "expand";
        }, this);      
    
        this.toggle = function () {
            this.expanded(!this.expanded());
        };
    };
    

    http://jsfiddle.net/madcapnmckay/XAzW6/

    Hope this helps.

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

Sidebar

Related Questions

I want to create a link like this: <a href=http://example.com>text</a> and replace the behavior
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
Ideally I want a function something like the following (this example doesn't compile): void
looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
Let's say this page www.example.com/mypage returns some html that I want to parse in
I'll try and give an example what i want: (this isn't what I'm doing,
For Actionscript 2.0 Let's say this page www.example.com/mypage returns some html that I want
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I want to ask about this function in matlab dicomread example : a =
For example, I want to search a word ' marple ', this should return

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.