Return to Snippet

Revision: 20194
at November 9, 2009 11:27 by flicity


Initial Code
$(document).ready(function() {
        $('#extlinks a').filter(function() {
         return this.hostname && this.hostname.split(":")[0] !== location.hostname.split(":")[0];
        }).addClass('externalLink');
      });


//css
.externalLink {
  background:url(/myiconpath/myicon.gif) top left no-repeat;
// set background position to suit your needs
  padding: 15px 0 0 0;
// set padding to width of icon plus the size of gap you would like
}

Initial URL
http://www.learningjquery.com/2008/08/quick-tip-dynamically-add-an-icon-for-external-links

Initial Description
This code appends a class of external to all all outbound links
It includes a fix for Safari which does not recognise internal links that use a different port

Initial Title
Adding class to external links

Initial Tags
links

Initial Language
jQuery