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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:54:05+00:00 2026-05-25T22:54:05+00:00

Relevant discussion . I understand I can build an array of references to elements/nodes.

  • 0

Relevant discussion.

I understand I can build an array of references to elements/nodes. I realize also that I could use the neat trick of treating an array like a heap (index 2n and 2n+1 for children) to build a (potentially wasteful) binary search tree using it.

But all that’s still not enough for the premature optimizer in me. Besides, implementing a BST is going to be bug prone.

Here’s my question. Can I somehow use an element reference as index into javascript’s hashes (which are objects, or vice versa?). If not, can I conjure up a unique string from an element reference, which I can then use as my hash key? If not, how the hell does jQuery do it?

  • 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-25T22:54:05+00:00Added an answer on May 25, 2026 at 10:54 pm

    The easiest option is to just use your own attribute on the DOM object:

    var element = document.getElementById("test");
    element.myData = "whatever";
    

    Here’s the general idea behind how jQuery’s .data() function works that you could use in your own plain javascript. It uses one custom attribute on the object and then stores everything else in a data structure indexed by the value of that custom attribute.

    var idCntr = 0;   // global cntr
    
    var data = {};
    var element = document.getElementById("test");
    var id = element.uniqueID;
    if (!id) {
        id = idCntr++ + "";
        element.uniqueID = id;
    }
    data[id] = "whatever";
    
    
    // then some time later, you can do this
    var element = document.getElementById("test");
    console.log(data[element.uniqueID]);   // whatever
    

    It is a bit more involved to store multiple attributes for a given object in the data object, but this is the general idea.

    And, if you can use jQuery, it’s trivial:

    $("#test").data("myData", "whatever");  // sets the data
    
    console.log($("#test").data("myData"));   // retrieves the data
    

    If you want to really see how jQuery’s .data() works, you can step through the first call to set data and then retrieve it when using the unminified jQuery. It’s easy to see what it does.

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

Sidebar

Related Questions

Here are the relevant models: User Product Order A User can sell or buy
How can I pull relevant packet information from a JpCap packet? I am trying
I'm having trouble extending a base class that extends Ordered[Base]. My derived class can't
Foreword tl;wr: This is a discussion. I am aware that this question is more
After reading the discussion on operator< for std::weak_ptr, I can't see any reason why
My question is related to this other discussion . I'm trying to implement that
Edit1: I realize this is hard to understand this question without having an insight
It is relevant to a technical discussion I'm participating in.
I have a web application where users can create topics and also comment on
Relevant Tables #One# +----------+ +--------------+ |Quotations| ---> |PurchaseOrders| +----------+ | +--------------+ <One> | <Many>

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.