Results 1 to 3 of 3

Thread: How to reference a css stylesheet in javascript

  1. #1
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default How to reference a css stylesheet in javascript

    1) Script Title: Animated Collapsible DIV v2.2

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...edcollapse.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?

    PS
    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
    Code:
    <a href="javascript:faq.sweepToggle('contract')">
    the cma converts it to
    Code:
    <a href="/portal/jsp_includes/leaving_county_site_disclaimer.jsp?ref=javascript:faq.sweepToggle('contract')">
    .

    Any other suggestions?

    thanks
    Last edited by lazywolfy; 06-24-2009 at 09:30 PM. Reason: Wrong section...this probably belongs in javascript or html section.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Animated Collapsible DIV by default actually doesn't reference any inline or external .css files. What CSS are you referring to?
    DD Admin

  3. #3
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    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:

    Code:
    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);
    please move this topic to appropriate section. sorry.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •