Created
October 20, 2011 14:35
-
-
Save Mottie/1301306 to your computer and use it in GitHub Desktop.
Add jQuery renameAttr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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