1

When should I use one or the other?

The only difference I noticed is that with a click event

var $sth = $('.selector').data('sth'); seems to be cached, while

var $sth = $('.selector').attr('data-sth'); gets newly assigned every click.

What is the use-case for .data('sth'); ?

PrimuS
  • 2,505
  • 6
  • 33
  • 66

0 Answers0