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

The Archive Base Latest Questions

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

Is it at all possible to get the corresponding element (or elements) that a

  • 0

Is it at all possible to get the corresponding element (or elements) that a data (model) instance was bound to?

For example, I have an array of ‘Person’ objects stores in a ViewModel property.

I bind the ViewModel to the view which renders it, eg:

<div class="people" data-bind="template: { foreach: people }">
    <a href="#" class="person" data-bind="text: name"></a>
</div>

I then bind some event handlers via jQuery:

$container.on('click', '.person', function(e){
    e.preventDefault();
    self.showPerson( ko.dataFor(this) );
});

In my showPerson method I would save a reference to the model. I /could/ also a save a reference to the element, but I don’t want to if I don’t have to.

self.showPerson = function(person) {
    // can i get the corresponding element from the 'person' model?
};

Anyone got any ideas?

  • 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-04T13:07:16+00:00Added an answer on June 4, 2026 at 1:07 pm

    Your syntax and use of $container with jquery and the second argument of ‘.person’ is unfamiliar to me, but in your click handler, isn’t this the element that was clicked? Couldn’t you pass that to your showPerson method also?

    $container.on('click', '.person', function(e){
        e.preventDefault();
        self.showPerson( ko.dataFor(this), this );
    });
    
    self.showPerson = function(person, element) {
        // can i get the corresponding element from the 'person' model?
    };
    

    I don’t know of a way off the top of my head to get the elements that an observable is bound to, but it could be several different elements. You could have a text box for ‘name’, display the name in a span, use it in a computed, have subscribers, and use name().length in a calculation in another binding for instance.

    That said, if you use the debug version of knockout, you can see that your observables have a _subscriptions property that might have what you’re looking for. The minified version is some single character I think.

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

Sidebar

Related Questions

Is it possible to get all/latest tweets from twitter public list? Example list: https://twitter.com/#!/thecaucus/u-s-senate
I have a function calc_dG that, for any array corresponding to a short DNA
I'm wondering if it is at all possible to get the total duration of
Is there a way to get all possible values from a MySQL enum column?
I would like to get all possible available currencies. Java 7 had provided such
In T-SQL you can use CROSS APPLY to get all possible variations between the
I would like to be able to get a list of all possible files
Possible Duplicate: get all available fonts from google font api How we can retrieve
Possible Duplicate: Get all files from VSS for a given date? I need to
Is it possible to get all div's within a page using jQuery including nested

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.