Appending style sheet elements

Discussion in 'Javascript' started by delraydog@gmail.com, Dec 1, 2005.

  1. Guest

    I'm writing a reusable JavaScript library which needs to set certain
    styles in a document. The document may have an existing stylesheet
    definition either by a link or by an existing stylesheet declaration in
    the documents head section.

    How can I use JavaScript to append my own style sheet information to a
    possibly already existing stylesheet definition?

    Thanks!

    Cliff.
     
    , Dec 1, 2005
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > I'm writing a reusable JavaScript library which needs to set certain
    > styles in a document. The document may have an existing stylesheet
    > definition either by a link or by an existing stylesheet declaration in
    > the documents head section.
    >
    > How can I use JavaScript to append my own style sheet information to a
    > possibly already existing stylesheet definition?
    >


    Try quirksmode:

    <URL: http://www.quirksmode.org/dom/changess.html >




    --
    Rob
     
    RobG, Dec 1, 2005
    #2
    1. Advertising

  3. Neredbojias Guest

    With neither quill nor qualm, quothed:

    > I'm writing a reusable JavaScript library which needs to set certain
    > styles in a document. The document may have an existing stylesheet
    > definition either by a link or by an existing stylesheet declaration in
    > the documents head section.
    >
    > How can I use JavaScript to append my own style sheet information to a
    > possibly already existing stylesheet definition?


    That's no problem. The latest style is the one honored. Add something
    like the following to the <head> section:

    <script type="text/javascript">
    <!--
    document.write('<style type="text\/css">\n#ct1 { width:95.2%; text-
    align:justify; }\n<\/style>\n');
    document.close;
    //-->
    </script>

    PS: This example is from one of my pages, has been checked and works.

    --
    Neredbojias
    Contrary to popular belief, it is believable.
     
    Neredbojias, Dec 2, 2005
    #3
  4. Neredbojias wrote:

    > With neither quill nor qualm, quothed:
    >> How can I use JavaScript to append my own style sheet information to a
    >> possibly already existing stylesheet definition?

    >
    > That's no problem. The latest style is the one honored.


    That is not entirely true. It depends on the specificity of the selectors
    used.

    > Add something like the following to the <head> section:
    >
    > <script type="text/javascript">
    > <!--
    > document.write('<style type="text\/css">\n#ct1 { width:95.2%; text-
    > align:justify; }\n<\/style>\n');
    > document.close;


    document.close() refers to a Function(-like) object. The Call Operator ()
    is _not_ optional for it to be called. Therefore, the object reference is
    only evaluated and nothing is called, preventing the harm it would do
    otherwise.

    > //-->
    > </script>
    >
    > PS: This example is from one of my pages, has been checked and works.


    It probably breaks in NN4 due to the Run-Length bug. It breaks in a
    conforming HTML UA due to nonsensical comment delimiter strings, and
    it breaks in XHTML due to either comment delimiters (empty `script'
    element), or markup delimiters like `<' in PCDATA, or document.write()
    not supported there in recent UAs.

    BTW: Not all / characters in script data have to be escaped, only
    those in an HTML document that would form the ETAGO delimiter </


    F'up2 cljs

    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    3,761
    Thomas 'PointedEars' Lahn
    Dec 2, 2005
  2. Replies:
    0
    Views:
    811
  3. Replies:
    0
    Views:
    562
  4. jital

    appending excel sheet

    jital, Apr 28, 2008, in forum: Java
    Replies:
    1
    Views:
    527
    Roedy Green
    Apr 29, 2008
  5. Manoj Rout
    Replies:
    3
    Views:
    239
Loading...

Share This Page