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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:10:50+00:00 2026-05-27T12:10:50+00:00

So html elements can have attributes which will say something about the element. However,

  • 0

So html elements can have attributes which will say something about the element. However, these attributes are visible to anyone which could be bad if the data stored is sensitive. So can you store data in/on a html element with javascript/jquery or something else?

Like (using jQuery) if I had a #apple div and wanted to append a secret data (red) to it. Could I do something with this logic?:

$("div#apple").secret = "red";
or 
$("div#apple").data = { "color": "red" };
alert("The color of an apple is " + $("div#apple").secret);

I’m guessing one way to do this is create a jQuery function to bind to the html element and then bind the data to that function, but is there an easier/better way of pulling something like this off?

Also, I know that html 5 allows custom attributes, is there any version of html that allows/does the above without javascript/jquery?

  • 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-27T12:10:51+00:00Added an answer on May 27, 2026 at 12:10 pm

    Yes, jQuery’s .data() is what you need. It stores the data in a key-value way.

    You can use it in this way:

    $('.where').data('key', 'value');
    $('.where').data('dog', {'name': 'fritz'});
    

    And then you can retrieve it in this way:

    $('.where').data('key'); // value
    $('.where').data('cat'); // null, nothing exists with the cat key
    $('.where').data('dog'); // object, {'name': 'fritz'}
    

    It works storing all the data you what in its internal object jQuery.cache.

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

Sidebar

Related Questions

how can i do. i have many html elements on page. after clicking on
Using the HTML Agility Pack , how can I remove all HTML attributes, elements,
An HTML <body> element can only contain block elements such as <p> . If
How can I find out which FORM an HTML element is contained within, using
Can anyone explain to me why can we style the element html ? What
I have an array of object names. These objects are HTML elements. I want
I have custom Question objects which I render into html form elements. I want
Can anyone recommend a good CMS which will output PURE RDF documents (I don't
ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink() , @Html.BeginForm()
How can I parse a html document or just a html element in order

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.