JQuery – Add an icon for external links

This trick is pretty simple and good for usability. If links are linking to external website, an image will be displayed next to the link. Dynamically add an icon for external links

$(document).ready(function() {
$('#extlinks a').filter(function() {
return this.hostname && this.hostname !== location.hostname;
}).after(' <img src="/images/external.png" alt="external link">');

Leave a Reply

Your email address will not be published. Required fields are marked *