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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:12:05+00:00 2026-06-18T12:12:05+00:00

I have two nested div and 2 button inside each div: <div id=d1> <button

  • 0

I have two nested div and 2 button inside each div:

<div id="d1">
    <button data-bind="click:x">
        invoke x
    </button>
    <div id="d2">
        <button id="Q_btn" data-bind="click:x">
            invoke x
        </button>
    </div>
</div>

and 2 view model that binding as:

var viewModel1 = {
    x : function() {
        alert('from model1')
    }
}

var viewModel2 = {
    x : function() {
        alert('from model2')
    }
}

ko.applyBindings(viewModel2, document.getElementById('d2'));
ko.applyBindings(viewModel1, document.getElementById('d1'));

Now when i click on button inside d2 (Q_btn), 2 alert raise, the first one says ‘from mode2’ and the second one says ‘from model1’.
i want when i click on Q_btn only the first alert happen.

Note: in my project i load some html page on divs. each div has own view model. til now everythings are OK (each div work with own viewmodel and no conflict happen) but in case of nested div the above problem were occurred.

i appreciate your help

  • 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-18T12:12:05+00:00Added an answer on June 18, 2026 at 12:12 pm

    I don’t think that there’s any way of doing what you want in the way that you are suggesting. I’d recommend that you look at implementing a publisher/subscriber pattern here, either rolling your own (using something like jquery.pubsub), or there’s an extension called knockout-postbox you could use.

    This would enable you to have your view models nicely decoupled, yet allow them to talk to each other.

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

Sidebar

Related Questions

I have a that contains two nested div's. One of the nested div's contains
I have a div which contains two nested divs, one that specifies a height
I have two inner divs which are nested inside a wrapper div. I want
I have two nested div s that are supposed to both be 400 pixels
I have a KnockoutJS template that looks something like this: <div data-bind=template: {name: 'testTemplate',
I have a div with two nested divs inside, the (float:left) one is the
I have an ASP.NET MVC 4 view that dynamically loads two nested partials into
I have two nested packages that I am calling via fast_cgi. From the first
I have a navigation bar that has two dropdowns (as nested ul's). I'm trying
I have two classes (MVC view model) which inherits from one abstract base class.

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.