Created
May 26, 2012 17:04
-
-
Save brandonb927/2794652 to your computer and use it in GitHub Desktop.
JS: Get favicons beside links
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
/* JS */ | |
function getDomain(url) { | |
return url.match(/:\/\/(.[^/]+)/)[1]; | |
} | |
$("a[href^='http']").each(function() { | |
$(this).css({ | |
background: "url(http://www.google.com/s2/u/0/favicons?domain=" + getDomain(this.href) + | |
") left center no-repeat", | |
"padding-left": "20px" | |
}); | |
}); | |
| |
/* LESS/CSS */ | |
a { | |
display: block; | |
text-decoration: none; | |
padding: 5px; | |
} | |
/* HTML */ | |
<a href=http://github.com>GitHub</a> | |
<a href=http://css-tricks.com>CSS-Tricks</a> | |
<a href=http://www.google.com>Google</a> | |
<a href=http://www.brandonb.ca>Brandonb.ca</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment