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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:36:06+00:00 2026-05-13T08:36:06+00:00

What I need to do is be able to store some piece of data

  • 0

What I need to do is be able to store some piece of data about an element.

For example, lets say I have a list item <li>, and I want to store some data about it in the element, like “This is element 1 from XYZ”.

The only way I know how to do this (which I don’t want to do if I can avoid) is this:

<li id='item1'>
  Item 1
  <!--This is element 1 from XYZ-->
</li>

<script>
  // read it something like this
  var e = document.getElementById('item1').innerHTML; 
  // then parse out the comment, etc.
  // --
</script>

What I really want is something like this (which I am fairly certain is not possible):

// example
<li id='item1' userdata='This is element 1 from XYZ'>Item 1</li>

.. of course, I would like to be able to access it somehow via javasscript.

Alternatively, is there some other way to achieve this?

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-13T08:36:06+00:00Added an answer on May 13, 2026 at 8:36 am

    You can access your userdata=”” attribute from JavaScript. Just do:

    var theData = document.getElementById('item1').getAttribute('userdata');
    

    If you want to do it the HTML5 way, then you would use attributes named data-*, e.g.:

    <li id='item1' data-foo='This is element 1 from XYZ'>Item 1</li>
    

    that way it will still be valid (i.e., it’ll make you feel better for not using an invalid attribute). New browsers will support accessing the data-* attributes like so:

    var theData = document.getElementById('item1').data.foo;
    

    but I don’t think that is implemented widely enough to rely upon yet.

    If you do want to store the data in a comment (although I’d advise going the attribute route instead) you could do something like:

    var e = document.getElementById('item1');
    var n = e.firstChild;
    while (n && n.nodeType != Node.COMMENT_NODE) {
        n = n.nextSibling;
    }
    // now n.nodeValue will have the comment contents
    

    (No guarantees about whether IE likes any of the above.)

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

Sidebar

Related Questions

I've come to the point where I need to store some additional data about
I need to store some arbitrary XML data in an XHTML HEAD element, that
I need to be able to store some information about the user and I
I have a need to store some meta-data in a node.js application I am
I need to be able to store data for a php application in a
I want to store some objects and then be able to retrieve them later
I need to store some data that is essentially just an array of key-value
Let's assume I need to store some data of unknown amount within a database
I have a table in which I need to store some serialized json strings
I need to utilize the Cache object in ASP.NET to store some data with

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.