Javascript – jQuery append not working(adding css to head)

append, javascript, jquery

I want to add a stylesheet to the head of a page, but for some reason it doesn't work. Should i use something else, instead of append?

the code

$('head').append('<link rel="stylesheet" href="test.css" type="text/css" class="test" />');

maybe some usefull info, i am using firefox 3.6.17

Best Solution

You could try something like this:

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