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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:18:27+00:00 2026-06-10T05:18:27+00:00

Using jQuery 1.7.2, how do I update the data-* attrs in my elements when

  • 0

Using jQuery 1.7.2, how do I update the data-* attrs in my elements when the data model is updated?

For example:

$('el').attr('data-x', 400);
var data = $('el').data( );
data.x += 100;

Changing the $(el).data() does not seem to push the changes back to the elements’ data-* attrs.

Why would I want this? I would like to use the built in jQuery selectors with up-to-date 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-10T05:18:28+00:00Added an answer on June 10, 2026 at 5:18 am

    There’s no reason to push data back onto the element’s attribute unless you’re going to be working directly with the attribute values (such as in a non-jQuery plugin). The changes only happen client-side, so it’s much more performant to simply cache the values retrieved from the [data-*] attributes.

    If you absolutely must update the attribute value, you should use the .attr() method.

    Additionally, when retrieving data, it’s important to know that the .data() method will try to figure out what sort of data type your content is:

    <div data-foo="bar" data-baz="0" data-fizz='{"a":"b"}' data-bool="true"></div>
    
    $('div').data('foo');       //returns "bar"
    $('div').attr('data-foo');  //returns "bar"
    
    $('div').data('baz');       //returns 0
    $('div').attr('data-baz');  //returns "0"
    
    $('div').data('fizz');      //returns {"a":"b"} as an object
    $('div').attr('data-fizz'); //returns "{\"a\":\"b\"}"
    
    $('div').data('bool');      //returns true
    $('div').attr('data-bool'); //returns "true"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have updated my jSon object using the code <script type=text/javascript > jQuery(document).ready(function($){ var
I am using JEditable jquery plugin to update some data on my webpage. After
I'm using jQuery to update an image source $(#myImage).attr(src, imagePath); Immediately after, I try
I am using jquery load method to update divs , it works great until
Is is possible to update the text 'changethis' in below div using jquery ?
I am trying to update the <p> tag using jquery, however, when I click
I'm trying to update a database using html form + jquery + php When
Using jquery, how can I change the color of these elements to red if
I've put 2 elements next to eachother. Both of them are using the jQuery
I am using JQuery to update some input values - and on the screen

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.