Last active
October 4, 2020 16:57
Star
You must be signed in to star a gist
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 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