public
Last active

jQuery function that appends a class to each designated element by pulling it from a tag attribute.

  • Download Gist
jQuery.fn.attrToClass
1 2 3 4 5 6 7 8 9 10 11 12
//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");
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.