473,786 Members | 2,380 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 2155

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
1878
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
8915
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
2199
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...
7
3859
by: Fabien LE LEZ | last post by:
Hello, I'd like to put, on a web page, a "place" where the user can type a rather long text, with automatic coloring of each word (e.g. a color depending on the number of letters of the word). The only solution I could think of is rather ugly: a <textareafor the user to type in, and behind the <textarea>, one <spanfor each word, with the same text and font, and a colored background. I've put it there:...
1
2488
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
1814
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
2545
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
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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...
1
10108
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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
8988
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...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.