I am using this script to randomly load a style sheet on load.
But I would also like to have a button on the site that can run the script so the user can load a new style by clicking on a button instead of F5.
Any suggestions on how to write this?
Cheers!
var link = [];
link[0] = "css/style1.css";
link[1] = "css/style2.css";
link[2] = "css/style3.css";
$(function() {
var style = link[Math.floor(Math.random() * link.length )];
$('<link />',{
rel :'stylesheet',
type:'text/css',
href: style
}).appendTo('head');
});
Just put your code in that button:
HTML:
JS:
Assuming you have defined necessary variables on top of your script: