Created
September 24, 2009 07:35
-
-
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.
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
//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