Reputation: 1671
I created a custom dataset attribute on an element node (El.dataset.FTid=i;), where i is a number, but when I use (El.attributes) to look at it, the attribute name is reported as (data--f-tid) instead of (data-FTid) as expected. Very strange! Firefox 63.0.3 (64bit).
Upvotes: 0
Views: 69
Reputation: 14927
When setting properties of the dataset
collection of a DOM element, they will automatically be converted to the corresponding attribute names following these rules:
camelCase to dash-style: The opposite transformation, that maps a key to an attribute name, uses the following rules:
Restriction:
A dash must not be immediately followed by an ASCII lowercase letter a to z (before the transformation);
a prefix data- is added;
any ASCII uppercase letter A to Z is transformed into a dash followed by its lowercase counterpart;
other characters are left unchanged.
In your case, you should probably use:
El.dataset.ftId = i;
which will be accessible via:
El.getAttribute('data-ft-id')
Upvotes: 1