Skip to content

Instantly share code, notes, and snippets.

@akmur
Created November 3, 2014 10:35
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 akmur/64180ab6aaa9f608b7e1 to your computer and use it in GitHub Desktop.
Save akmur/64180ab6aaa9f608b7e1 to your computer and use it in GitHub Desktop.
Remove All Data Attributes
$('div').each(function(index, el) {
// Fetch an array of all the data
el = $(el);
var data = el.data(),
i;
// Fetch all the key-names and put them in a variable called keys
var keys = $.map(data , function(value, key) { return key; });
// Loop through the keys, remove the attribute if the key contains "lorem".
for(i = 0; i < keys.length; i++) {
el.removeAttr("data-" + keys[i]);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment