According to the documentation:
.data ()
The .data () method allows us to attach data of any type for DOM elements in a way that is safe from circular references and, therefore, from Leak memory.
.attr ()
The .attr () method receives the attribute value only for the first element in a consistent set.
So you want to use the .attr () method, for example:
var xxx = $(this).attr('data-what') || 'default_value';
source share