Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  108] [ 4]  / answers: 1 / hits: 11205  / 11 Years ago, wed, january 8, 2014, 12:00:00

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 as in this example:



<button class=action data-actionClass=user data-actionMethod=delete data-actionRequest=/user/delete/user-id/1 data-actionComplete={reload:users}>Delete User #1</button>
<div id=users data-reloadRequest=/user/index> ... </div>


Pretty unobtrusive way to harness Jquery for actions, but when I call $('.action').data(), the attribute names are converted to lowercase.



Any workarounds for this?



I never though JavaScript variables should have dashes in them, and I can't understand why jQuery is internally doing this for me? Or maybe it is HTML5?


More From » jquery

 Answers
1

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.



[#48903] Tuesday, January 7, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanap

Total Points: 413
Total Questions: 82
Total Answers: 99

Location: South Georgia
Member since Mon, Oct 19, 2020
4 Years ago
susanap questions
Mon, Oct 17, 22, 00:00, 2 Years ago
Sat, Jun 12, 21, 00:00, 3 Years ago
Tue, Aug 11, 20, 00:00, 4 Years ago
Tue, May 5, 20, 00:00, 4 Years ago
Tue, Jan 15, 19, 00:00, 5 Years ago
;