Appending style sheet elements

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?



Re: Appending style sheet elements wrote:
Quoted text here. Click to load it

Try quirksmode:



Re: Appending style sheet elements

With neither quill nor qualm, quothed:

Quoted text here. Click to load it

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

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

Contrary to popular belief, it is believable.

Re: Appending style sheet elements

Neredbojias wrote:

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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


Site Timeline