...

View Full Version : How to reference a css stylesheet within javascript?



lazywolfy
06-24-2009, 10:14 PM
Does anyone know of any websites/tutorials/resources/information on how to reference a css stylesheet within javascript code, or actually add all the css into the js?
Reason being is because I'm using a content management application at work that automatically 'validates' (removes) any css. So I'm trying to add it into the javascript as a workaround.

Any other suggestions?

Thanks

//Edit: Wouldn't you know it, as soon as i posted this thread I tried a different google search and I found the code below which seems to work just fine, however I'm not a javascript guru so even though it works fine, is there anything that should be changed below to optimize it? If not, i'll just use it as is.


var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'path_to_css.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum