Thursday, 22 August 2013

Appending a stylesheet to the head of an html document using JavaScript

Appending a stylesheet to the head of an html document using JavaScript

pI'm attempting to add jQuery to an html document before downloading it. I
need to append the following to the head of the document:/p precodelt;link
rel=stylesheet type=text/css
href=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/themes/base/jquery-ui.css/gt;
/code/pre pI have attempted to use the following to do this, but all I end
up with is an empty pair of tags in the document:/p precodevar head =
content.document.getElementsByTagName('head')[0]; var jqstyle =
document.createElement(link); jqstyle.rel = stylesheet; jqstyle.type =
text/css; jqstyle.href =
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/themes/base/jquery-ui.css;
head.appendChild(jqstyle); /code/pre pCould anybody tell me what I need to
do differently?/p pThank You/p

No comments:

Post a Comment