Apparently adding in the document body is considered a bad practice by W3C standards. The same for adding
One way to solve that issue is to load the CSS
with .get() and, appending it to the head tag only when needed:
JQUERY
var css = "foobar.css";
var callback = function() {
alert("CSS is now included");
// your jquery plugin for a navigation menu or what ever...
};
$.get(css, function(data){
$("").appendTo(document.head);
callback();
});
The callback
function is useful to allow script
code that depends on the CSS
file to be properly formatted, to run only after the CSS
as been added!