Does jQuery internally convert HTML5 data attribute keys to lowercase?

后端 未结 2 1527
星月不相逢
星月不相逢 2020-12-03 01:17

I am trying to conform my JavaScript coding style to my Zend coding style as much as possible, which is using camelCase. So, in my HTML5 data attributes, I am naming them a

2条回答
  •  醉话见心
    2020-12-03 02:11

    If you use

    data-action-method="delete"
    

    then you can access the attribute with

    $('.action').data('actionMethod')
    

    This is part of the HTML5 DOM API:

    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.

提交回复
热议问题