Connecting Tech Pros Worldwide Help | Site Map

writing to head using js and dom

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 10th, 2006, 02:45 PM
drewmania001@gmail.com
Guest
 
Posts: n/a
Default writing to head using js and dom

Hi everyone!

i've been reading up on access to the dom via js (i'm new to this dom
stuff)

i understand tutorials and info such as
http://developer.mozilla.org/en/docs....createElement

my problem: i'd like js to create the code for a stylesheet in the head
of the docuement!

i'm not sure how do do this (or if it can be done)

can i create the following...

<link rel="stylesheet" type="text/css"
href="mystyle.css" />

OR

<style type="text/css">
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
</style>

using the dom or anything else in js alone?...or am i fighting a losing
battle.

(what i really want at the end of the day is to detect the browser and
use a css file according to that file, either with js or php)

any suggestions or pointers?


  #2  
Old May 10th, 2006, 03:15 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: writing to head using js and dom



drewmania001@gmail.com wrote:

[color=blue]
> can i create the following...
>
> <link rel="stylesheet" type="text/css"
> href="mystyle.css" />[/color]

Yes, create the link element as follows
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'mystyle.css';
then insert as needed
document.getElementsByTagName('head')[0].appendChild(link);



--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old May 11th, 2006, 09:45 AM
drewmania001@gmail.com
Guest
 
Posts: n/a
Default Re: writing to head using js and dom

WOW it worked!!! (not that i didnt have faith in you or anything)/

one comment, i believe "LINK" is a keyword so i just changed the var to
mylink and vala sucess!

thanks so much i had the first part down pat it was
getElementsByTagName and using the array to append the child i needed
help with.

once again thankyou, thankyou, thankyou...now i can move on with my
life!

  #4  
Old May 19th, 2006, 11:55 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: writing to head using js and dom

drewmania001@gmail.com wrote:
[color=blue]
> one comment, i believe "LINK" is a keyword[/color]

You believe wrong. However, it is not a bad idea to avoid such
ambiguities in order to avoid problems in case a broken script
engine/AOM/DOM interferes.

Please quote the minimum of what you are replying to next time.


PointedEars
--
When the power of love overcomes the love
of power, the world will know peace.
-- Jimi Hendrix
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.