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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:43:32+00:00 2026-05-25T11:43:32+00:00

If you put a data- attribute on an element: <div id=’x’ data-key=’value’> then you

  • 0

If you put a “data-” attribute on an element:

<div id='x' data-key='value'>

then you can get the value via the jQuery “.data()” method:

alert($('#x').data('key')); // alerts "value"

The library uses a consistent camel-case converter for attribute names with embedded dashes:

<div id='x' data-hello-world="hi">

alert($('#x').data("helloWorld"));

The camel-case converter is a jQuery “global” function:

alert($.camelCase("hello-world")); // alerts "helloWorld"

However this all breaks down when the attribute name has a name with a single letter surrounded by dashes:

<div id='x' data-image-x-offset='50px'>

alert($('#x').data('imageXOffset')); // undefined

That’s a little weird, because:

alert($.camelCase('image-x-offset')); // "imageXOffset"

So what’s wrong? I think it has something to do with the mechanism used to go the other direction, converting an already camel-case name back into the dashed form. I can’t pinpoint it in the code however.

Seems to be the same in 1.6.2 as in 1.6.3. (The form “image-x-offset” can be used to get the data, by the way.)

edit — if, for a given element, you access via the dashed form before attempting the camel-case form, then it works (and that tells me that this is definitely a bug 🙂

  • 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-25T11:43:33+00:00Added an answer on May 25, 2026 at 11:43 am

    You’re right. The issue seems to be with the regex they use for conversion from camelCase to dashed.

    rmultiDash = /([a-z])([A-Z])/g;
    

    …as used here:

    var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
    

    …which results in:

    data-image-xoffset
    

    …instead of:

    data-image-x-offset
    

    Demo: http://jsfiddle.net/TLnaW/

    So when you use the dashed version, when it looks for an attribute, it finds it with no need for a conversion, and then adds the camelCase version to the elements data in jQuery.cache.

    Subsequent attempts will then work because the correct camelCase is now there, so it no longer attempts to get it as an attribute, and therefore no longer needs the faulty regex.

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

Sidebar

Related Questions

I'm trying to get data from a resource with jquery's ajax and then I
I need to put a JSON object into an attribute on an HTML element.
I want to change the value of data-confirm attribute on a button (submit) based
We have a REST API which clients routinely POST and PUT data to. When
I'm trying to put this data type in a Haskell Set, but I don't
This answer suggested i should put my data in JS instead of a textarea.
I have a file containing lots of data put in a form similar to
i just could not figure out how i will put my data on a
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
Using sql server 2000, I would like to take my production data and put

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.