Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load a random CSS file
<!-- this will print one of these:
<link rel="stylesheet" type="text/css" href="css/bk1.css" />
<link rel="stylesheet" type="text/css" href="css/bk2.css" />
<link rel="stylesheet" type="text/css" href="css/bk3.css" />
<link rel="stylesheet" type="text/css" href="css/bk4.css" />
<link rel="stylesheet" type="text/css" href="css/bk5.css" />
<link rel="stylesheet" type="text/css" href="css/bk6.css" /> -->
<script type="text/javascript" src="RANDOM_CSS_javascript.js"></script>
<script type="text/javascript">
RANDOM_CSS.printlinktag();
</script>
var RANDOM_CSS = {
cssfiles : ['bk1.css','bk2.css','bk3.css','bk4.css','bk5.css','bk6.css'],
pathtocss : 'css/',
getrandomcss : function() { return this.cssfiles[Math.floor(Math.random()*this.cssfiles.length)]; },
getlinktag : function() { return '<link rel="stylesheet" type="text/css" href="'+this.pathtocss+this.getrandomcss()+'" />'; },
printlinktag : function() { document.write(this.getlinktag()); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.