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

changing css colors

How do I change the CSS colors via JavaScript DOM? Let me explain...

I am working on a Windows application (in C#) that displays some HTML.
In one place the HTML is a status window. What happens is the static
HTML page is embedded into the application. The static page displayed
and then the C# code gets a hold of the HTML DOM from the web browser
and updates what pieces need to be updated.

What I need to do now is change the colors of everything on the static
page. At present there is an embedded CSS style in the HTML and all
the colors are defined there. Using the DOM, via C# code, how do I
change the colors of everything?

1: Can I simply update the CSS and it will auto magically happen? If
so, how does one update the CSS via the DOM?
2: Do I need to go to each individual item and change the color there?
3: Is there a better way to do this all the way around?

Sam

Oct 27 '06 #1
4 1780

Sam Carleton wrote:
How do I change the CSS colors via JavaScript DOM? Let me explain...

I am working on a Windows application (in C#) that displays some HTML.
In one place the HTML is a status window. What happens is the static
HTML page is embedded into the application. The static page displayed
and then the C# code gets a hold of the HTML DOM from the web browser
and updates what pieces need to be updated.

What I need to do now is change the colors of everything on the static
page. At present there is an embedded CSS style in the HTML and all
the colors are defined there. Using the DOM, via C# code, how do I
change the colors of everything?

1: Can I simply update the CSS and it will auto magically happen? If
so, how does one update the CSS via the DOM?
2: Do I need to go to each individual item and change the color there?
3: Is there a better way to do this all the way around?

Sam
Hi Sam,

you can't do this via C# but only via JavaScript because C# works on
your server. JavaScript is made to dynamically change/manipulate your
DOM tree.

For exampleto change the font color of an element with id "myElement":

document.getElementById('myElement').style.color = 'red';

To change the color of all DIV element which have the className
"whatever", you should use prototype (a JavaScript library that extends
JS language):

$$('div.whatever').each(function(element) {
element.style.color = 'red';
});

^ This works in all current browsers, there are other JS methods to
change a node of your CSS definition (would be easier) but it's not
compatible to all browsers.

But there's a way to change the complete StyleSheet (CSS) file to make
your page look change.

I hope this wil help you.

Andi

Oct 27 '06 #2
As your css is embedded into the page you can have it modified. It's
something like /html/head/style. But it will be an unparsed text value
which you will have to parse by yourself.

It seems to me the better solution is to use classes. Like

/* in your css */
body.default * {
color: red;
}

body.changed * {
color: green;
}
.... than ...
<body class="default">..

In this case you will only have to change the class attribute of an
appropriate element (body in this case).

Sam Carleton wrote:
How do I change the CSS colors via JavaScript DOM? Let me explain...

I am working on a Windows application (in C#) that displays some HTML.
In one place the HTML is a status window. What happens is the static
HTML page is embedded into the application. The static page displayed
and then the C# code gets a hold of the HTML DOM from the web browser
and updates what pieces need to be updated.

What I need to do now is change the colors of everything on the static
page. At present there is an embedded CSS style in the HTML and all
the colors are defined there. Using the DOM, via C# code, how do I
change the colors of everything?

1: Can I simply update the CSS and it will auto magically happen? If
so, how does one update the CSS via the DOM?
2: Do I need to go to each individual item and change the color there?
3: Is there a better way to do this all the way around?

Sam
Oct 27 '06 #3
ASM
Sam Carleton a écrit :
How do I change the CSS colors via JavaScript DOM? Let me explain...

I am working on a Windows application (in C#) that displays some HTML.
In one place the HTML is a status window. What happens is the static
HTML page is embedded into the application. The static page displayed
and then the C# code gets a hold of the HTML DOM from the web browser
and updates what pieces need to be updated.

What I need to do now is change the colors of everything on the static
page. At present there is an embedded CSS style in the HTML and all
the colors are defined there. Using the DOM, via C# code, how do I
change the colors of everything?

1: Can I simply update the CSS and it will auto magically happen? If
so, how does one update the CSS via the DOM?
2: Do I need to go to each individual item and change the color there?
3: Is there a better way to do this all the way around?
I think best way is to have 2 titled alternate styles sheets embedded in
your files.
Then you'll just have to switch between both (or more).
<link rel="alternate stylesheet" type="text/css"
href="../../css/yellow.css" media="all" title="Yellow">
<link rel="alternate stylesheet" type="text/css"
href="../../css/blue.css" media="all" title="Blue">
Here functions for several alternate styles sheets :

function setActiveStyleSheet(title) {
var i, a, main='';
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1) {
if(a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title)
a.disabled = false;
}
}
}
}

function getActiveStyleSheet() {
var i, a, main = 'Defaut';
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") != -1
&& a.getAttribute("title")
&& !a.disabled) {
main = a.getAttribute("title");
return main;
}
}
return null;
}
Oct 27 '06 #4
I recommend a book ISBN 0-321-43032-8 entitled "Javascript and Ajax for the
web, sixth edition."

The title is very misleading as the book has scant information about using
Ajax. It is however excellent with regard to Javascript, e.g. DHTML. The
entire book is basically several dozen well written and clearly explained
snippets of Javascript for general page tasks. It should have been called
something like "DHTML Snippets Simplified with the Last Chapter Ajax
Overview"

I found this book at the library and intend to buy it myself...

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
"Sam Carleton" <sc*******@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
How do I change the CSS colors via JavaScript DOM? Let me explain...

I am working on a Windows application (in C#) that displays some HTML.
In one place the HTML is a status window. What happens is the static
HTML page is embedded into the application. The static page displayed
and then the C# code gets a hold of the HTML DOM from the web browser
and updates what pieces need to be updated.

What I need to do now is change the colors of everything on the static
page. At present there is an embedded CSS style in the HTML and all
the colors are defined there. Using the DOM, via C# code, how do I
change the colors of everything?

1: Can I simply update the CSS and it will auto magically happen? If
so, how does one update the CSS via the DOM?
2: Do I need to go to each individual item and change the color there?
3: Is there a better way to do this all the way around?

Sam

Oct 27 '06 #5

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

Similar topics

0
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello',...
2
by: Matt | last post by:
I'm having problems changing the text colors in an edit box in my program. Here's what I'm trying to do, under WM_CREATE I have the following: ClockFace = CreateWindowEx(0, "EDIT", "0.0.00",...
1
by: Firewalker | last post by:
I am attempting to change the backColor property on the previously instantiated buttons FROM a listbox_doubleClick event. I thought it would be something like this: If...
4
by: JoelW | last post by:
Let's say you're programming in VB.NET, and you have: Dim str1 As String Dim str2 As String Dim str3 As String str1 = "I am red" str2 = "I am yellow" str3 = "I am dark green"
3
by: Vinay | last post by:
Hi All: I'd like to fill a set of controls with colors (by probably setting control.backcolor) that are changing gradually - e.g. start from dark green and endup with lightgreen. How can I do...
1
by: batesy67 | last post by:
Hi All, We have a CCTV application here written in C# that is meant to run in 256 colors. It is called from another application via a button click. The CCTV app is meant to always be on top,...
1
by: JJ | last post by:
With all the skinning possibilities of asp.net 2.0 I am surprised that I cannot (easily) change the colour of a controls scrollbars/border or a dropdownlist's arrow. I realise that I may have to...
4
by: Sam Carleton | last post by:
How do I change the CSS colors via JavaScript DOM? Let me explain... I am working on a Windows application (in C#) that displays some HTML. In one place the HTML is a status window. What happens...
6
Fary4u
by: Fary4u | last post by:
Hi i'm in deadend i don't know how to do the job i'm bit confused ? i'm just thinking how to write the code ? i've got dropdown list of colors & whn i select the colors it's stored into database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.