jQuery doesn't returns the new data-attribute

前端 未结 2 1438
误落风尘
误落风尘 2021-01-23 07:00

I\'m trying a very simple task working with data-attr and jQuery, check this example:

Markup:

2条回答
  •  遇见更好的自我
    2021-01-23 07:42

    Working demo http://jsfiddle.net/DDv8U/

    • API: http://api.jquery.com/data/ - try using this $(div).data('name', ' - Testing 2');

    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'));
    });
    

提交回复
热议问题