473,770 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1813

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.getEle mentById('myEle ment').style.co lor = '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.whateve r').each(functi on(element) {
element.style.c olor = '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 setActiveStyleS heet(title) {
var i, a, main='';
for(i=0; (a = document.getEle mentsByTagName( "link")[i]); i++) {
if(a.getAttribu te("rel").index Of("style") != -1) {
if(a.getAttribu te("title")) {
a.disabled = true;
if(a.getAttribu te("title") == title)
a.disabled = false;
}
}
}
}

function getActiveStyleS heet() {
var i, a, main = 'Defaut';
for(i=0; (a = document.getEle mentsByTagName( "link")[i]); i++) {
if(a.getAttribu te("rel").index Of("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*******@gmai l.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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
1876
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', brightyellow, blue) The module would automatically interpret the above as curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
2
8914
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", WS_CHILD|WS_VISIBLE|WS_BORDER, 125, 75, 300,
1
4108
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 Me.Controls.Item(iSeatNumber).BackColor.Equals(Color.White) Then Me.Controls.Item(iSeatNumber).BackColor.Equals(Color.CornflowerBlue) 'End If
4
9578
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
1155
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 this? I suppose I will need to use the Hex values for the colors? Any help will be much appreciated!
1
2197
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, however it may not necesserily have focus. We have found that when the CCTV application has focus the background application does not flash - we have 8 bit flashing colors on the 'parent app'. The CCTV application has been built via bitmaps...
1
2486
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 do this via javascript, if it is possible, can anyone help me? I have found a way to chaange the scrollbars (see below) but not the drop down arrows nor borders:
4
2155
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 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...
6
2544
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 color Varibale is ComboName now the only problm is product price is fix ie ( 20$ ) & it's only 3 category ie ( intcat ). but the 1st 3 colors ie ( 1,2,3 ) is 5$ less then product price and next 4 colors ie ( 4,5,6,7 ( is 7$ less then...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9910
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.