0

Can anyone explain why this works: $('#someId').data('typeId', 2); $('#someId').data('type-id'); // will return 2

Here is the fiddle as well: http://jsfiddle.net/L6nLpgdb/

Thank you !

medowlock
  • 1,469
  • 1
  • 19
  • 25
  • 5
    read [html5 dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.dataset) - `for any dash (U+002D) followed by an ASCII lowercase letter a to z, the dash is removed and the letter is transformed into its uppercase counterpart;` - so it is because the spec says so – Arun P Johny Aug 20 '14 at 11:23

1 Answers1

1

check this link

The custom data attributes is transformed to a key for the DOMStringMap entry with the following rules:

    any dash (U+002D) is removed;
    any letter following a dash (U+002D), before its removal, is set in its uppercase counterpart.
Community
  • 1
  • 1
Amit Soni
  • 3,216
  • 6
  • 31
  • 50