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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:19:07+00:00 2026-06-11T18:19:07+00:00

If you try to change a data attribute value with data() method you don’t

  • 0

If you try to change a data attribute value with data() method you don’t get the same result as attr(data-key, data-value) method.

For example, I’m using data-hovered=true to store some state for the element. If you have some css styling for the element[data-hovered=true] selector, using data() method to assing the value true to data-hovered won’t have effect. Only using attr() this would have effect.

So what’s the difference between these two methods?

  • 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-11T18:19:08+00:00Added an answer on June 11, 2026 at 6:19 pm

    .data() is used to store data in an object, but as of the “release” of HTML5, it can also access data-* attributes on elements.

    However, it can not change these, as it is primarily used for storing data in objects etc, not physically on elements.

    Therefore attr() is the only way to change a value of an attribute on an element, such as data-* attributes.

    See:

    • jQuery Data vs Attr?
    • http://api.jquery.com/jQuery.data/
    • http://api.jquery.com/attr/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do i get the value of an html5 attribute using jQuery ? <button
I try to change a string into an object using eval but failed. var
When I try to change the default collation of a SQL Server instance using
example i try to change cell.accessoryView from picture1 to picture2 by fadein but my
I get this exception thrown whenever I try and submit data through a form
I have problem with c# script who change user AD password, when try change
I try to change the color from a UIPopoverControler on iOS 5. To do
I try to change the dimensions of the view in interface builder from the
im try to change my webrick to passenger with nginx but when i try
I try to change over htaccess from http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic.jpg to http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic1.jpg Here is my rules

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.