JavaScript Call Random CSS file
Someone talk to stack overflow like this : I am trying to rotate random CSS sheets via JS - I have the following script but when I am using it - it doesnt seem to work ? function getRand(){ return Math.round(Math.random()*(css.length-1)); } var css = new Array( '<link rel="stylesheet" type="text/css" href="css/1.css">', '<link rel="stylesheet" type="text/css" href="css/2.css">', '<link rel="stylesheet" type="text/css" href="css/3.css">', '<link rel="stylesheet" type="text/css" href="css/4.css">' ); rand = getRand(); document.write(css[rand]); Appreciate any help? The best answer is : Try to create the link element programmatically and appending it to the head function applyRandCSS(){ var css = ["css/1.css", "css/2.css", "css/3.css", "css/4.css"