Skip to content

Instantly share code, notes, and snippets.

@fleimisch
Created May 22, 2015 14:11
Show Gist options
  • Select an option

  • Save fleimisch/5603c527aa13d500f65c to your computer and use it in GitHub Desktop.

Select an option

Save fleimisch/5603c527aa13d500f65c to your computer and use it in GitHub Desktop.
Rename Attribute Name
jQuery.fn.extend({
renameAttr: function (name, newName, removeData) {
var val;
return this.each(function () {
val = jQuery.attr(this, name);
jQuery.attr(this, newName, val);
jQuery.removeAttr(this, name);
// remove original data
if (removeData !== false) {
jQuery.removeData(this, name.replace('data-', ''));
}
});
}
});
/* Usage Example */
$("*[data-cke-pa-onclick]").renameAttr('data-cke-pa-onclick', 'onClick');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment