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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:33:27+00:00 2026-06-12T16:33:27+00:00

I know understand more about how jQuery stores data. Is there any advantage to

  • 0

I know understand more about how jQuery stores data.

Is there any advantage to doing one or the other of these:

$('#editCity').data('href', "xx");
var a = $('#editCity').data('href');

or

$('#editCity').attr('data-href', "xx");
var a = $('#editCity').attr('data-href');

One more related question.

If I have this:

var modal = { x: 'xx', y: 'yy' };

Can I also store this using .data( .. ) ?

  • 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-12T16:33:29+00:00Added an answer on June 12, 2026 at 4:33 pm

    Storing property values directly on DOM elements is risky because of possible memory leaks. If you’re using jQuery anyway, the .data() mechanism is a wonderful and safe way to keep track of per-element information. It allows for storage of arbitrary JavaScript data structures too, not just strings.

    edit — when your HTML markup contains data-foo attributes, those are implicitly read when the keys are accessed. That is, if your HTML looks like this:

    <div id="div1" data-purpose="container">
    

    Then in jQuery:

    alert( $('#div1').data('purpose') ); // alerts "container"
    

    Furthermore, jQuery will also do some “smart” analysis of the attribute values. If a value looks like a number, jQuery will return a number, not a string. If it looks like JSON, it de-serializes the JSON for you.

    edit — here’s a good trick: in the Chrome developer console (the “Console” view), you can type JavaScript expressions and have them evaluated. The evaluation is always done in the context of the page you’re working on. If you select an element from the “Elements” view, then in the console the JavaScript symbol $0 will refer to that selected DOM element. Thus you can always inspect the “data” map for an element by going to the console and typing something like:

    $($0).data("something");
    

    The .data() function, if called with no parameters, returns all the key/value pairs:

    $($0).data();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know more about the different ways of solving Single Sign-On and
I guess this query is a little basic and I should know more about
Yes i know i should read more about memory management, did try to find
Hi I'm new in Javascript OO and want to know more about about inheritance.
I would like to understand more about how to capture if a user click
I was implementing the tower of hanoi problem to understand more about recursion. I
From a person wanting to know more about Windows Internals, reading the book Windows
I am trying to understand a little more about memory management. Knowing that I
I'd like to know more about the advantages and disadvantages of forking a github
I know what thread means and if I understand the event dispatching thread (EDT)

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.