473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Appending style sheet elements

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
3 1662
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anne van Kesteren | last post by:
Ok, here it goes. Originally I submitted this proposal to www-style. Since I don't get feedback there, I think I missed a few (maybe a lot) of points. Proposal:...
1
by: David Bradbury | last post by:
I may be thinking about this the wrong way, but here goes: In my style sheet I've specified that bullet points should use a specific image rather than just be default bullet points. However, at...
2
by: mjansen.merge.emed | last post by:
Is there a way to override inline within the <bodya style of an element but not do it with a style attribute on the element? I know CSS Inheritance works for some styles, but doesn't appear to...
10
by: pamelafluente | last post by:
Hi, this time I am trying to add a style on the fly.I wish equivalency with this one (only the menuItemStyle line): <head> <style type="text/css" media="screen"> ... some static styles ......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.