Last active
October 4, 2020 16:57
-
-
Save ppisarczyk/50e08b067229cb51092d7d9b40903900 to your computer and use it in GitHub Desktop.
From https://css-tricks.com/snippets/jquery/automatically-discover-document-links-and-apply-classThis will look through every a element on the page. If the href attribute of it has a .doc, .xls, or .pdf in it, it will apply the appropriate class name to it (e.g. class="doc")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Will iterate through every 'a' tag element with an 'href' attribute on the page. | |
// If the href attribute of it has a .doc, .xls, or .pdf in it, | |
// it will apply the appropriate class name to it (e.g. class="doc") | |
$('a[href]').each(function() { | |
if((C = $(this).attr('href').match([.](doc|xls|pdf)$))) { | |
$(this).addClass(C[1]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment