I need to add an link to an external css file in my header using an external javascript file. Don't ask why; I just need to do it. document.write()
doesn't work btw.
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "external.css");
document.getElementsByTagName("head")[0].appendChild(element);
Alternative one liner:
document.head.insertAdjacentHTML( 'beforeend', '<link rel=stylesheet href=/ext.css>' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With