$("a[href $='.pdf']" ).addClass("linkIconPDF");
$("a[href *='.pdf#']").addClass("linkIconPDF");
$("a[href *='.pdf;']").addClass("linkIconPDF");
$("a[href *='.pdf?']").addClass("linkIconPDF");
$("a[href $='.txt']" ).addClass("linkIconTXT");
$("a[href *='.txt#']").addClass("linkIconTXT");
$("a[href *='.txt;']").addClass("linkIconTXT");
$("a[href *='.txt?']").addClass("linkIconTXT");
So far so good, but how can it be simplified to match any file type?
Is it possible to do some regex grouping to match all possible file types like this?
$("a[href $='.([a-zA-Z0-9]{2,4})']" ).addClass("linkIcon$1");
Test script: http://jsfiddle.net/k2jqn/
Demonstration: http://jsfiddle.net/k2jqn/4/