View Full Version : How to reference a css stylesheet in javascript

06-24-2009, 07:15 PM
1) Script Title: Animated Collapsible DIV v2.2

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm

3) Describe problem: Hi, I'm trying to use the 'Animated Collapsible DIV v2.2' within our Content Management Application. I can enter the javascript just fine but when I add the css (entire css, or src link) the html validator/editor tool automatically removes it.

Is there a way to add/merge the css into the javascript to avoid having to enter it in separately?

I also tried using other javascript codes similar to the Animated Collapsible DIV v2.2 like the Switch Content Scripts, but when I add something like this
<a href="javascript:faq.sweepToggle('contract')"> the cma converts it to
<a href="/portal/jsp_includes/leaving_county_site_disclaimer.jsp?ref=javascript:faq.sweepToggle('contract')">.

Any other suggestions?


06-24-2009, 08:47 PM
Animated Collapsible DIV by default actually doesn't reference any inline or external .css files. What CSS are you referring to?

06-24-2009, 09:27 PM
OOPS, I got the Animated Collapsible Div script confused with a different script. Sorry!
Anyhow, I found what I was looking for which was a way to reference a css stylesheet in javascript:

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';

please move this topic to appropriate section. sorry.