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

The Archive Base Latest Questions

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

I’m trying to add collapsible panel functionality to my knockout template. Basically, I want

  • 0

I’m trying to add collapsible panel functionality to my knockout template.

Basically, I want to add an image to the header div, that when clicked toggles the image url (to show a “plus” or “minus” icon) and toggles the visibility of the following div.

My template (with the required bindings I hope) is below:

{{each $data}}
<div id="wrapper" class="option-wrapper group show">
    <div class="option-head group">
    <img data-bind="click: showDescription attr: { href: url }>
        <h3 data-bind="text: Name"></h3>
        <select class="option-select" data-bind="options: Values, optionsText: 'value', optionsValue: 'key', value: Selected" />
    </div>
    <div class="option-description" data-bind="visible: showDescription html: Description"></div>
</div>
{{/each}}

I’m just unsure how to tackle the viewmodel. Any help would be greatly appreciated.

  • 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-01T22:38:28+00:00Added an answer on June 1, 2026 at 10:38 pm

    Okay. First option: Do you really need knockout to control the panels and whether they are opened or closed? If not then you could consider just using knockout to render the content and then using something like the jQuery accordion to handle the panels opening and closing.

    However, if that does not work in your scenario, I would do something along the lines of:

    {{each $data}}
    <div id="wrapper" class="option-wrapper group show">
        <div class="option-head group">
            <span data-bind="click: toggleDescription, css: { 'isOpen': showDescription, 'isClosed': !showDescription() }"></span>
            <h3 data-bind="text: Name"></h3>
            <select class="option-select" data-bind="options: Values, optionsText: 'value', optionsValue: 'key', value: Selected" />
        </div>
        <div class="option-description" data-bind="visible: showDescription, html: Description"></div>
    </div>
    {{/each}}
    

    (Notice how I have changed the <img> to a <span>)

    Add the following function to your view model:

    toggleDescription: function() {
       viewModel.showDescription(!viewModel.showDescription());
    }
    

    And then define the css styles for the span:

    .isOpen{ background-image: url(../images/open.gif); }  
    .isClosed { background-image: url(../images/closed.gif); }  
    

    I’m coding off the top of my head here but hopefully that should give you the gist on how to proceed.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.