Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
Something went wrong with that request. Please try again.