By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,401 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,401 IT Pros & Developers. It's quick & easy.

Appending style sheet elements

P: n/a
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 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
de*******@gmail.com 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
Dec 1 '05 #2

P: n/a
With neither quill nor qualm, de*******@gmail.com 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.
Dec 2 '05 #3

P: n/a
Neredbojias wrote:
With neither quill nor qualm, de*******@gmail.com 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
Dec 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.