Auto add a class to link files (pdf,doc,external)


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(document).ready(function(){
  2. $("a[href$='.pdf']").addClass("pdf");
  3. $("a[href$='.doc']").addClass("doc");
  4. //Add external link icon to external links -
  5. $('a').filter(function() {
  6. //Compare the anchor tag's host name with location's host name
  7. return this.hostname && this.hostname !== location.hostname;
  8. }).addClass("external").attr("target","_blank");
  9. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.