Appending style sheet elements

D

delraydog

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.
 
R

RobG

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 >
 
N

Neredbojias

With neither quill nor qualm, (e-mail address removed) 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.
 
T

Thomas 'PointedEars' Lahn

Neredbojias said:
With neither quill nor qualm, (e-mail address removed) quothed:

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top