function openFile(file) {
var extension = file.substr( (file.lastIndexOf('.') +1) );
switch(extension) {
case 'jpg':
case 'png':
case 'gif':
alert('was jpg png gif');
break;
case 'zip':
case 'rar':
alert('was zip rar');
break;
case 'pdf':
alert('was pdf');
break;
default:
alert('who knows');
}
};
openFile("somestring.png");
I got this piece a code from another question posted here, but im unsure how to implement it for my purpose. I want to check the hrefs of every link and place the appropriate icon for the file type.
Use
.eachfunction:It allows you to iterate through the matched sets of elements.