jQuery doesn't returns the new data-attribute

前端 未结 2 1427
误落风尘
误落风尘 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:45

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

提交回复
热议问题