Skip to content

Instantly share code, notes, and snippets.

@stylephreak
Created September 24, 2009 07: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 stylephreak/192588 to your computer and use it in GitHub Desktop.
Save stylephreak/192588 to your computer and use it in GitHub Desktop.
jQuery function that appends a class to each designated element by pulling it from a tag attribute.
//Appends a class to each designated element by pulling it from a tag attribute.
jQuery.fn.attrToClass = function(attribute) {
$(this).each(
function(intIndex){
$(this).addClass($(this).attr(attribute));
});
};
$(document).ready(function(){
// designate the tag and the attribute to be extracted
$("input").attrToClass("type");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment