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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:43:33+00:00 2026-05-17T02:43:33+00:00

I need to add some function that returns a value to a dom element.

  • 0

I need to add some function that returns a value to a dom element. I tried to use jquery’s bind method, but it seems that events always return a jquery collection.

My goal is creating a flashcard application. So I created flashcard objects that contain methods and variables including the dom element representing the flashcard on the page. As long as I only work on the dom element (moving around etc.) everything is fine but at some point I need to get a reference to the actual card object to access the additional functionality. Here is the constructor I came up with:

    function make_flashcard {  
        var dom_element;
        function some_function() {}
        /*...other variables and functions */

        var card = {
            dom_element: dom_element,
            some_function: some_function,
            /*...other variables and functions */
        };

        return card;
    }

later I’d like to be able to invoke some_function from outside, maybe like this:

    card = dom_element.get_card();
    card.some_function();

I tried the following three approaches of defining get_card inside make_flashcard, all of which failed:

    dom_element.get_card = function () {
        return card;
    };

    dom_element.prototype.get_card = function () {
        return card;
    };

or

    dom_element.bind("get_card", function () {
        return card;
    });

and then calling

    card = dom_element.trigger("get_card");

If you have any tips to get this running I’d be very happy. Or do you think the whole thing should be approached differently?

Thanks in advance,
Dominik

`

  • 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-05-17T02:43:34+00:00Added an answer on May 17, 2026 at 2:43 am

    What if you extended the jQuery collection prototype instead?

    $.fn.flashcard = function () {
        var self = this;
    
        if (!this.data("flashcard")) {
            this.data("flashcard", {
               element: self,
               some_function: some_function,
               /*...other variables and functions */
            });
        }
    
        return this.data("flashcard");
    };
    

    Then you could use it like:

    var card = $("div.myClass").flashcard();
    card.some_function();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add some functionality to the jQuery UI autosearch function. The problem
After inserting new html to DOM,I need to add some listeners to it. But
i need to add some functionality to an asp.net application that allows the positioning
i'm writing an application that need to add some events to a calendar in
I need to add some total rows to a table. The code I am
I need to add some accordian style expand/collapse handles to a series of parent
I need to add some lightweight syntactic sugar to JavaScript source code, and process
i need to add some text DIV's on each slide of a Nivoslider. I
I have a form and I need to add some data from database before
In One of my application i need to add some image in video. so

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.