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?