Dynamically load Twitter Tweet and Facebook Like button

This is a good technique to use as it saves having to load loads of share buttons on every page load which often slow the page down. Just had to do this and needed a few lines to get it working.

Whether you have the code hidden somewhere on your page before it's needed or load it via AJAX is irrelevant, but once it's included on the page, you need the following code to initialise the buttons. 

if(typeof twttr != 'undefined')
{
	twttr.widgets.load();
}
FB.XFBML.parse(document.getElementById('container'));

If you add one Tweet button dynamically it seems to initialise itself, but later ones need this code. As well as this, 'twttr' won't exist until the first one is created but will after, so we only need to run that once it's defined; isn't needed for the first one anyway.

For the Facebook one, you need to specify the ID of a container of the post or something, and it'll find any FB elements inside that it needs to initialise.

After that, should work fine.