473,414 Members | 1,946 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,414 software developers and data experts.

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?

May 10 '06 #1
3 1123


dr**********@gmail.com wrote:

can i create the following...

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


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/
May 10 '06 #2
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!

May 11 '06 #3
dr**********@gmail.com wrote:
one comment, i believe "LINK" is a keyword


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
May 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Brian Burgess | last post by:
Hi all, Anyone see anything wrong with the following: *************************************************************** <%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit Dim nAcctNbr Dim...
6
by: Christopher Benson-Manica | last post by:
I have some markup like the following: <form> <table> <script> <!-- Write the table markup //--> </script> </table> <form>
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
3
by: VMI | last post by:
I'm having trouble writing several records from an XML file into an html file. The problem is that it only outputs one record to the html file. I need to export all the records in the xml file to...
6
by: guy | last post by:
Does .NET have a class or set of functions that facilitate the creating and writing of html files? I have been creating files in streams and constructing html strings and writing them out but it...
2
by: amaltasb | last post by:
I have a CGI script on server which process a form and writes its content on a file like fp = open(fname, 'w') fp.write('<HTML><HEAD><TITLE>Cool...
1
by: Billy | last post by:
Hi All, I'm attempting to use the MapNetworkDrive <snippedbelow from entire code below with very poor performance results. Basically, I have very small 73kb text files that are rewritten daily...
0
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but...
7
by: Fuji | last post by:
Dear Sir, Why this code can't be ran in my Internet Explorer? Am I doing wrong in using ActiveXObjectScripting.FileSystemObject")? <html> <head><title>Reading/Writing Text File in...
12
by: LayneMitch via WebmasterKB.com | last post by:
Hello everyone. I'm currently learning Javascript and doing a few exercises. One problem I'm working on takes an array of names from an xml file using Ajax and writes it to...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.