Why jQuery .data() function is not accessing HTML5 camel-case data attribute -
i have button in web page: <button class="slidetoggle" data-slidetoggle="slider">slidetoggle</button> when button clicked trying access data stored inside data-slidetoggle attribute useing following code, nothing. $('body').on('click', '.slidetoggle', function(){ alert($(this).data('slidetoggle')); }); but works when use: alert($(this).attr('data-slidetoggle')); this problem occurs when use camel-case data attribute. new html5 , jquery , can not figure out going wrong it. all previous answers miss 1 thing: can work existing html structure. consider this: $('body').on('click', '.slidetoggle', function(){ alert($(this).data('slidetoggle')); // wait, what? }); to understand happens here, it's crucial check following lines in jquery source code : name = "data-" + key.replace( rmultidash, "-$1" ).tolowercase(); data = elem.get...