javascript - Data attribute changes not detected with jQuery -


i changing data-demo attribute of div element , when want check in event, shows me initial value of instead of current value.

this code using:

$('#showvalue').click(function(){     alert($('.value').data('demo')); });  $('.update').click(function(){    $('.value').text('updated').attr('data-demo', 'updated'); }); 

why happening?

here's fiddle example talking about: http://jsfiddle.net/f5cpm/

thanks.

the jquery .data() functions aren't supporting html5 dataset functionality, rather load in html5 dataset data own data collection. in consequence updates dataset changing attribute not reflected in jquery internal data collection.

in other words, either need consequently use dataset.demo, $().data("demo") or $().attr("data-demo"). advantage of second being cross browser of course , part of jquery if you're using jquery rest of application.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -