Skip to content

Instantly share code, notes, and snippets.

@hergaiety
Created September 26, 2014 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hergaiety/a17fb0d69ade53da2e47 to your computer and use it in GitHub Desktop.
Save hergaiety/a17fb0d69ade53da2e47 to your computer and use it in GitHub Desktop.
Ensures data-* updates the attribute when the real data is updated.
/**
* Ensures the data-* is updated visually when the data is updated by jQuery
* Example: $('.foo').data('bar', 'value').trigger('changeData');
*/
$(document).on('changeData', '.foo', function(e) {
$(this).attr('data-bar', $(this).data('bar'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment