.data() vs .attr()

Test element [data-foo-bar=' test ']

So you see the .data() is not bound to the attribute, per se. It is only using the data-attr to initialize the jQuery object cache ( $.cache ) initially...

See using-jquerys-data-apis and stackoverflow.com/a/18844822