Skip to content

Instantly share code, notes, and snippets.

@Mottie
Created October 20, 2011 14:35
Show Gist options
  • Save Mottie/1301306 to your computer and use it in GitHub Desktop.
Save Mottie/1301306 to your computer and use it in GitHub Desktop.
Add jQuery renameAttr
// http://wowmotty.blogspot.com/2011/10/jquery-rename-attribute-renameattr.html
// *********
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-','') );
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment