$('a[href]').each(function() { if((C = $(this).attr('href').match(/[.](doc|xls|pdf)$/))) { $(this).addClass(C[1]); } });