I'm modifying some legacy code and I found a web page that loads the JQuery library only to perform the following (this is inside a <script> tag in the <body> of the page):
$(document).ready(function(){
//Once the document is ready, run the following code
$("head").append($("<link rel='stylesheet' href='style-"+myCSS+".css' type='text/css' media='screen' />"));
});
I want to convert this code to regular JavaScript and remove JQuery (I'm not against the use of JQuery, I'm against the idea of having to load 90+Kb only to do that).
My idea, but I'm not a JS expert, is to use (in the same position in the page):
headReference.innerHTML = "<link rel='stylesheet' href='style-" + myCSS + ".css' type='text/css' media='screen' />";
Is there any better solution?
Any help is appreciated.
myCSSvariable come from?appendadds the HTML content to the node, while your solution replaces it. You can use the+=operator, or create a dummy<div>, put the content there and appending its children toheadReference.