Forum Moderators: open

Message Too Old, No Replies

Simple question

         

gsmith

8:40 am on Dec 6, 2004 (gmt 0)

10+ Year Member



Some demo script that I downloaded includes the following code:


<script language="JavaScript" type="text/javascript">
<!--
document.write("<link rel=\"stylesheet\" href=\"style/style.css\">");
// -->
</script>

My question is: Why not just include the <link> element in the HTML code? What benefit is there to dynamically adding this element to the HTML document by means of script?

Thanks

Bernard Marx

8:47 am on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Possibly none, but there is a use for this.

The CSS being loaded is only of any use if Javascript is enabled, and would be counterproductive if Javascript is disabled. A layered presentation, for instance, would call on rules that position the content, and hide a large proportion of it. If javascript is off, then that sheet isn't loaded, the content isn't layered or hidden, but all in plain view instead.