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

The Archive Base Latest Questions

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

I have html that looks something like this: <div> <table> <tr onclick=show();> <td class=cell>Click

  • 0

I have html that looks something like this:

<div>
    <table>
        <tr onclick="show();">
            <td class="cell">Click to open</td>
        </tr>
    </table>
</div>
<div style="display:none; position:absolute; left:150px" id="hiddenDiv">
    <table data-bind="with: someProperty">
        <tr onclick="hide();">
            <td class="cell" data-bind="text:message"></td>
        </tr>
    </table>
</div>
<input type="button" value="Color cells" onclick="colorCells()" />

And my JavaScript looks like this:

    function show() {
        vm.someProperty(vm.list[1]);
        $("#hiddenDiv").fadeIn("slow");
    }
    function hide() {
        $("#hiddenDiv").fadeOut("slow");
    }
    function colorCells() {
        $(".cell").css("background-color", "Yellow");
    }

    function ViewModel() {
        this.list = [new SubModel("item 1"), new SubModel("item 2")];
        this.someProperty = ko.observable(this.list[0]);
    }

    function SubModel(msg) {
        this.message = msg;
    }

    var vm = new ViewModel();

    $(function () {    
        ko.applyBindings(vm);
    });

I set up a jsFiddle here.

Now the problem is, when you click the button, all the table cells with class “cell” should have their background color changed. However, if the hidden div isn’t visible, then when it is made visible, it’s background color is still white. The reason for this seems to be because I’m changing the property that is used in a “with” binding that wraps the hidden cell. It seems when you change the property bound with “with”, it resets the style for it’s subitems.

(If that makes no sense, do this on the jsFiddle. Click the button, then click the “Click to open” cell. Notice that “item 2” isn’t highlighted. Click the button again and it’ll be highlighted. Now click the “Click to open” cell again, notice that “item 2” is no longer highlighted. Now remove the line that sets “someProperty” in the show function and repeat the experiment. “item 1” is now highlighted correctly regardless of whether or not it was visible when you click the color cells button)

Is this by design? Is there a way to work around it so that changing a property used by “with” doesn’t reset the style?

  • 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:34:13+00:00Added an answer on June 1, 2026 at 7:34 pm

    The correct way to solve this problem, IMHO, would be put the color also as an observable, which can be changed onclick of the button. I have the update jsfiddle here

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

Sidebar

Related Questions

So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
I have some HTML that looks like this: <div class=product> Content In Here <div
I have some html that looks like this: <div class=block> <div id=item1></div> <div id=item2></div>
If I have some HTML that looks like this: <div id=text> This is some
I have an html table that looks like this in a standard HTML 4.01
The HTML looks something like this: <li class=divider> <div> ...(maybe more divs)... <div class=content>
I have some HTML that looks like this, <div id=mb_contents style=visibility: visible; opacity: 1;
I have a webpage looks something like this: <html> ... <div id=menu> ... <ul
I have a KnockoutJS template that looks something like this: <div data-bind=template: {name: 'testTemplate',

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.