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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:32:22+00:00 2026-06-13T23:32:22+00:00

I am trying to associate some private data with DOM elements. Rather than adding

  • 0

I am trying to associate some “private” data with DOM elements. Rather than adding that data to the DOM element itself (I’d like to avoid changing the DOM element), I have a separate data object that I want to use as a map.

Rather than:

document.GetElementById('someElementId').privateData = {};

I want to do

internalPrivateDataMap[document.GetElementById('someElementId')].privateData = {};

Not all the elements have an id field, and some are created dynamically, so I can’t use the id as the key.

This works fine for most elements, but for “a” elements, the key being used seems to be the href of the element, I think because the DOM defines a toString() function for a elements.

The result of this is that if I have two “a” elements with the same href, they are sharing privateData, which I don’t want.

My current workaround is to generate an internal uniqueID I can use as a key, but that requires me to modify the DOM element, which I am trying to avoid.

  • 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-13T23:32:24+00:00Added an answer on June 13, 2026 at 11:32 pm

    As you noticed, this doesn’t work reliably and I know no way to make it work without either giving every element a (generated) ID or at least assign a unique ID to a new custom element field; DOM nodes simply don’t have the necessary properties to work as keys in a map.

    So you really have these solutions left:

    • Assign each element a generated ID unless it already has one
    • Assign a unique ID to a new private field. That way, you can keep the memory impact per DOM node small and still keep your private data in a different place. Don’t forget that you need to clean the private data somehow when the DOM elements are deleted.
    • Use something like jQuery which has element.data() to read and put private data into a DOM element
    • Use your own element.privateData = {}; Note that you still need cleanup for event handlers which keep references to the element or you will have unexpected memory leaks.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with some rather sensitive data, so I want to be ABSOLUTELY sure
im trying to retrieve some data using a reader in vb.net. I dont have
I have some seeds in my rails app that I am trying to get
I have a data of Element class. I'm trying to write its values to
I'm grabbing a list of events from a database and am trying to associate
This is my first time making a hash table. I'm trying to associate strings
I am trying to have an element index view displaying the associated projectname (
Now I am trying to build a store that associates with google books for
I'm trying to associate a video file to a record with a bunch of
I'm trying to use CFBundleDocumentTypes to associate a custom file extension with my application.

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.