Skip to main content

Dynamically Change Favicon Using jQuery

By July 1, 2016Blog, Javascript, jQuery, Snippets
Allure Web Solutions Code Snippet

Changing a favicon dynamically (on demand) is surprisingly easy. It takes just one line of jQuery code. However we want to make it into a function, so it takes 3 lines. And here they are…

function changeFavicon(src) {
    $('link[rel="shortcut icon"]').attr('href', src)
}

And this is how you use it…

changeFavicon('//google.com/favicon.ico');

Super easy, right?

Demo

allure

Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017