Skip to content Skip to sidebar Skip to footer

Jquery Doesn't Returns The New Data-attribute

I'm trying a very simple task working with data-attr and jQuery, check this example: Markup:
JS $(function(){ var div = $('div');

Solution 1:

You are changing the attribute but this doesn't automatically update the data. This works:

$(function(){
    var div = $('div');
    div.append(div.data('name'));
    div.data('name', ' -  Testing 2');
    div.append(div.data('name'));
});

Solution 2:

Working demohttp://jsfiddle.net/DDv8U/

rest should fit the need :)

code

$(function(){
    var div = $('div');
    $(div).append($(div).data('name'));
    $(div).data('name', ' -  Testing 2');
    $(div).append($(div).data('name'));
});

Post a Comment for "Jquery Doesn't Returns The New Data-attribute"