Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Appending style sheet elements

Reply
Thread Tools

Appending style sheet elements

 
 
delraydog@gmail.com
Guest
Posts: n/a
 
      12-01-2005
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.

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      12-01-2005
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
 
Reply With Quote
 
 
 
 
Neredbojias
Guest
Posts: n/a
 
      12-02-2005
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.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-02-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
appending excel sheet jital Java 1 04-29-2008 04:04 AM
Content Page specific style style sheet rshillington@gmail.com ASP .Net 0 07-14-2006 03:45 PM
how to create a node set of elements through C++ code while executing a style sheet and process the created node set. pvssvikas@gmail.com XML 0 01-25-2006 12:48 PM
Appending style sheet elements delraydog@gmail.com Javascript 3 12-02-2005 02:40 PM
dynamically appending elements to xml file Red Ogden XML 0 07-16-2003 08:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57