473,782 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing CSS classes

Is there any way I can dynamically (taking advantage of JavaScript) change
the properties for classes defined in CSS styles??
Let say there's a CSS class ".regtex" and it forces the browser to display
all elements of that class in red. Now I want to change this class so all
elements belonging to this class are displayed in blue, however I don't
want to change every single element, I just want to change the class'
properties. Is it possible??
Jul 23 '05 #1
2 1762
Pawe³ wrote:
Is there any way I can dynamically (taking advantage of
JavaScript) change the properties for classes defined in
CSS styles??
On dynamic visual browsers supporting the - document.styleS heets -
object (either in the Microsoft proprietary form or the W3C standard
form), yes.
Let say there's a CSS class ".regtex"
Class selectors introduce some potentially unexpected issues as the -
selectorText - may be a normalised equivalent such as
"*[class~=regtext]" rather than the more expected, original -
selectorText - ".regtex", so some extra effort (indexOf or regular
expression) may be necessary to identify the correct cssRule.
and it forces the browser to
display all elements of that class in red.
Browsers cannot be forced to do anything, you just get to offer a
suggestion of color that they may (but mostly will) follow.
Now I want to change this class so all elements
belonging to this class are displayed in blue,
however I don't want to change every single element, I
just want to change the class' properties.
Assigning alternative values to the properties of the class's rule in
the style sheet object in the stylesheets collection will alter the CSS
acting on a page, in dynamic vi9sual browsers supporting the -
document.styleS heets - collection. Other factors may override the actual
presentation to the user.
Is it possible??


Possible but not certain.

Richard.
Jul 23 '05 #2
Pawel wrote:
Is there any way I can dynamically (taking advantage of JavaScript) change
the properties for classes defined in CSS styles??
Let say there's a CSS class ".regtex" and it forces the browser to display
all elements of that class in red. Now I want to change this class so all
elements belonging to this class are displayed in blue, however I don't
want to change every single element, I just want to change the class'
properties. Is it possible??


One can access a collection of the style rules within a style sheet with
"cssRules" in order to alter any of its properties. Say your stylesheet
looked like this:

<style type="text/css">
a {color:green;}
..regtex {color:red;}
</style>

Then one can alter anchors to orange with:
document.styles heets[0].cssRules[0].style.color. = "orange"
And one can alter regtex classed elements to blue with:
document.styles heets[0].cssRules[1].style.color. = "blue"

You may also wish to look into "selectorTe xt" which is a string
containing the value of the selector, where in your case, selectorText
will contain ".regtex".

Another way is to call another class which will override previous
declarations. Here is an example which changes classes onmouseover:
http://www.home.golden.net/~richterf...4_Opera_1.html
Disregard the fixed box which describes an Opera redraw bug.

--
Gus
Jul 23 '05 #3

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

Similar topics

7
2258
by: John J. Lee | last post by:
I'm trying to change a base class of a big class hierarchy. The hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class that defines __getattr__ and __setattr__ that I need to override. Lots of classes derive from FtNode, often through further base classes, eg. HTMLDirectoryElement --> HTMLElement --> Element --> FtNode There are many leaf classes like HTMLDirectoryElement. The problem
2
1978
by: dcipher | last post by:
I'm in the process of rewritting my graphics library to be purely OO using C++. The following is a section of my heirarchy of classes: PImage // defines all basic graphics routines as virtual functions PImage8 // implements those routines for 8bpp PImage15 // and for 15bpp PImage16 // and 16bpp PImage24 // and so on...
0
1361
by: Robert-Paul | last post by:
Hi there. I have a problem after changing the assembly name of a class library. I have two projects in one solution: - a Windows application (.exe) - Class Library. There is a references from the windows application to the class library. All the classes from the both projects are arranged by the same namespace.
4
2447
by: Tony W | last post by:
Hi, I am trying to write a simple application to retrieve data from the Windows registry and insert it into textboxs on a windows form. So far I have one namespace containing two classess. The first class handles the form generation - (this was done using GUI form designer).
1
1821
by: Pablo | last post by:
I do not know like changing the color of bottom of: a menu, of the bar of the title of form, messagebox?
1
1685
by: William H. Burling | last post by:
i have a nest of vb.vanilla collections. CollectionofHotelData.item("great Pequot").item("2000").item(22) The above works. I wrote the code that constructs the nested collections and i can pull out anything i want within the collections of collections. However, I want to make my code more readable. Hence I would like to write it to result in the following:
2
1790
by: Oenone | last post by:
I could use a little advice to help prevent me making a possible mess of a project. :) In VB6, I once created a project that exposed a public interface class. I then Implemented this in various plug-in DLLs so that I could early-bind to the plug-ins by declaring objects of the interface class type. This worked fine, until one day I found that I needed to add a new method to the interface class. Of course, everything broke immediately...
7
1490
by: Brett Romero | last post by:
I'd like to copy a object1 into object2 so object2 can be manipulated. Object1 is coming form the middle layer into the UI layer. I'd like to rename a field in Object2 from "somethingID" to just "ID" and do this several times for a few middle layer objects. This will allow me to create generic<> lists and reference the field ID against many object2s that are similar to object1. The middle layer objects have ID fields with different...
6
6273
by: Adam C. | last post by:
We have a situation where we want a Swig-generated Python class to have a different base (not object). It doesn't appear that we can coerce Swig into generating the class we want at present (but we are still enquiring). Is it possible to dynamically change the base class to something else? Initial experiments appear to show it is not: -------------------------------- snip -------------------------------- pass
14
1979
by: Jeff | last post by:
Let's say we have this: <div class="some_class some_other_class"> Is it possible to change *one* of the classnames. Jeff
0
9479
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
10311
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
10146
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
9942
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
8967
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
6733
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();...
1
4043
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
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
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.