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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:33:33+00:00 2026-06-18T10:33:33+00:00

I am using KnockoutJS to create a simple rotate animation. I have some items

  • 0

I am using KnockoutJS to create a simple rotate animation. I have some items that contain a title and a description and I’m cycling trough these items.

Beneath the title and description I show some paging buttons and the active button should have a style applied.

However, the style for the paging button is not updated. Currently all paging buttons have the style applied instead of only styling the active page. I have created a jsFiddle that shows my problem.

What am I doing wrong?

JavaScript:

var AppViewModel = function () {
    this.currentItem = ko.observable();
    this.items = ko.observableArray([
    new Item("titleA", "descriptionA"),
    new Item("titleB", "descriptionB"), ]);

    this.tick = function () {
        var item = this.items.shift();
        if (item) {
            item.visible(false);
            this.items.push(item);
        }
        this.items()[0].visible(true);
    };

    this.tick();
    setInterval(function () {
        _this.tick();
    }, 1000);
}

var Item = function (title, description) {
    this.title = title;
    this.description = description;
    this.visible = ko.observable(false);
}

ko.applyBindings(new AppViewModel());

HTML:

<div data-bind="foreach: items">
    <div data-bind="visible:visible"> <span data-bind="text: title"></span>

        <blockquote data-bind="text: description"></blockquote>
    </div>
</div>
<nav>
    <ul data-bind="foreach: items">
        <li data-bind="style: { color: visible ? 'red' : 'black'} ">X</li>
    </ul>
</nav>
  • 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-18T10:33:35+00:00Added an answer on June 18, 2026 at 10:33 am

    I think that when you are using an observable in a test condition, you need to call it properly, as otherwise what you asking it to resolve is whether visible is a truthy condition in js, which a function is:

    <ul data-bind="foreach: items">
        <li data-bind="style: { color: visible() ? 'red' : 'black'} ">X</li>
    </ul>
    

    This seems to fix it for me in your jsFiddle.

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

Sidebar

Related Questions

I have a simple HTML table which is bound using knockoutJS. However, I've added
I am using John Resig's Simple JavaScript Inheritance to create a class that can
I have setup Knockoutjs to dynamically create an editable list of values using the
I found an example here to create a select list with optgroups using KnockoutJS.
I am trying to create a group of dropdowns using knockout out that allow
Ok getting frustrated on this one.... Using knockoutJS to do some visual interaction stuff.
I'm using KnockoutJs 2.2. I have a record which can have zero-to-many category associations.
I'm trying to create a custom binding in KnockoutJS using the raty jQuery plugin
I am trying to create a web page with a knockoutjs model, that allows
I have a mobile single-page web application that is built using jquery-mobile (jqm) and

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.