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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:48:40+00:00 2026-05-19T12:48:40+00:00

I was wondering if it was possible to assign values to an element object.

  • 0

I was wondering if it was possible to assign values to an element object. In this case, I wish to assign the returns from the setTimeout() function to an object within an element object.

For example:

var elem = document.getElementById('target');
elem.timeouts = new Object();
elem.timeouts.sometimeout = setTimeout('...', 1000);

So I could then do:

clearTimeout(elem.timeouts.sometimeout);

I know this might seem bad practice etc, but is it possible or will it cause browsers to catch fire and turn on their user etc.

Thanks.

  • 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-19T12:48:41+00:00Added an answer on May 19, 2026 at 12:48 pm

    DOM elements are Host objects (aka non-native) and as such they can do almost anything they want. It’s not guaranteed that your expandos will work. In particular IE used to have problems with them. It’s highly recommended to read this article:

    What’s wrong with extending the DOM by @kangax
    (it is from one of the Prototype.js developers who experienced the drawbacks of such bad habits. They’ve rewritten the whole library just to save themselfs from more headaches)

    Now if you add uniqueID to elements in non-IE browsers (IE has it by default) and then your data function becomes a simple lookup ~ O(1). The real information will be stored in a closure.

    It’s 2-4x faster than jQuery.data (test)

    data(elem, "key", "value");
    

    1.) Hash table

    var data = (function () {
        var storage = {};
        var counter = 1;
        return function (el, key, value) {
            var uid = el.uniqueID || (el.uniqueID = counter++);
            if (typeof value != "undefined") {
                storage[uid] || (storage[uid] = {});
                storage[uid][key] = value; // set
            } else if (storage[uid]) {
                return storage[uid][key]; // get
            }
        };
    })();
    

    2.) Array

    If you want to avoid expandos all together you can use an array to hold elements (but it’s slower)

    var data = (function () {
        var elements = [];
        var storage = [];
        return function (el, key, value) {
            var i = elements.indexOf(el);
            if (typeof value != "undefined") {
                if (i == -1) {
                    i = elements.length;
                    elements[i] = el;
                    storage[i] = {};
                }
                storage[i][key] = value; // set
            } else if (storage[i]) {
                return storage[i][key]; // get
            }
        };
    })();
    

    Array.prototype.indexOf (fallback)

    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function (item) {
            var len = this.length >>> 0;
            for (var i = 0; i < len; i++) {
                if (this[i] === item) {
                    return i;
                }
            }
            return -1;
        };
    }
    

    You’re welcome! 🙂

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

Sidebar

Related Questions

I was wondering if it is possible to do something like this: <uc1:TestControl ID=TestControl1
I'm wondering whether something like this is possible (and relatively easy to do), and
I'm wondering if its possible to add new class data members at run-time in
I was wondering if its possible to inject a thread into a remote app
I am wondering if it is possible to extract the index position in a
I was wondering if it is possible to not attach Excel sheet if it
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
I was wondering if it would be possible to retrieve the complete list of
I was wondering if it is possible to generate a core file, copy if
I'm wondering if it is possible to add methods in main program to an

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.