I've used some code I found on this thread about random divs to create a set of 3 Facebook Like buttons that are supposed to display at random on page load.
Problem is, it works fine in jFiddle but fails completely whenever I put it into production.
I borrowed this code from Nick Craver and made some very basic modifications, essentially just changing the class name from 'Image' to 'facebookLike':
HTML:
<div class="facebookLike">
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fcsuvolleyball&send=false&layout=button_count&width=80&show_faces=false&action=like&colorscheme=light&font&height=21&appId=150920871613500" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px;" allowTransparency="true"></iframe>
</div>
<div class="facebookLike">
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fcsurams&send=false&layout=button_count&width=80&show_faces=false&action=like&colorscheme=light&font&height=21&appId=150920871613500" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px;" allowTransparency="true"></iframe>
</div>
<div class="facebookLike">
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2FCoachJimMcElwain&send=false&layout=button_count&width=80&show_faces=false&action=like&colorscheme=light&font&height=21&appId=150920871613500" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px;" allowTransparency="true"></iframe>
</div>
jQuery code:
var divs = $("div.facebookLike").get().sort(function() {
return Math.round(Math.random()) - 0.5; //random so we get the right +/- combo
}).slice(0, 1)
$(divs).appendTo(divs[0].parentNode).show();
Here is a link to the page: http://www.csurams.com/test/facebook.html As you can see, nothing is happening.
I can't tell if the problem is related to the display:none; style rule or something else. However, when I remove the display:none; all three divs show...
Any help is greatly appreciated, been banging my head on my desk for a while now :-)