Dynamically loading CSS stylesheet based on conditions

So you want to load a CSS stylesheet based on some sort of validation? E.g

if(a == 1) { load stylesheet 1 }
if(a == 2) { load stylesheet 2 }

Below is the function which does just that:

<br></br>function getcss(cssfile){

loadcss = document.createElement('link')
loadcss.setAttribute("rel", "stylesheet")
loadcss.setAttribute("type", "text/css")
loadcss.setAttribute("href", cssfile)
document.getElementsByTagName("head")[0].appendChild(loadcss)

}

Have fun!
Cherio 🙂