473,800 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change class style

Hi,

Is it possible to dynamically change the style of a class instead of
just an individual element? If so could you point me in the right direction?

Robert
Jun 9 '06 #1
3 10644


Robert wrote:
Is it possible to dynamically change the style of a class instead of
just an individual element? If so could you point me in the right
direction?


You can change the style(s) of a certain rule in a stylesheet with IE
and with Netscape/Mozilla/Firefox. Opera however does not support that,
not sure about latest Safari/Konqueror.
There is a collection
document.styleS heets
for all stylesheets used (<style type="text/css"> element and <link
rel="stylesheet ">).
With IE/Win each stylesheet (e.g.
document.styleS heets[someIndex]
) has a collection
document.styleS heets[someIndex].rules
with Netscape/Mozilla/Firefox the name of the collection is W3C DOM
Level 2 compliant and is
document.styleS heets[someIndex].cssRules
You can loop through those rules and find the rule by its selectorText
and then change properties defined in the rule e.g.
document.styleS heets[someIndex].cssRules[1].style.backgrou ndColor =
'blue';

Finally an inefficient way to change a class style is to add a new
stylesheet as the last stylesheet. With Opera that is your only way e.g.
var styleElement = document.create Element('style' );
styleElement.ty pe = 'text/css';
styleElement.ap pendChild(docum ent.createTextN ode(
'.className { background-color: blue }'
));
document.getEle mentsByTagName( 'head')[0].appendChild(st yleElement);
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 9 '06 #2


Martin Honnen wrote:
You can change the style(s) of a certain rule in a stylesheet with IE
and with Netscape/Mozilla/Firefox. Opera however does not support that,


It looks as if Opera 9 is going to support document.styleS heets as the
latest weekly Opera 9 beta build
<http://my.opera.com/desktopteam/blog/show.dml/291397>
has that feature.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 10 '06 #3
Martin Honnen wrote:


Martin Honnen wrote:
You can change the style(s) of a certain rule in a stylesheet with IE
and with Netscape/Mozilla/Firefox. Opera however does not support that,

It looks as if Opera 9 is going to support document.styleS heets as the
latest weekly Opera 9 beta build
<http://my.opera.com/desktopteam/blog/show.dml/291397>
has that feature.


Okay, thanks!
Jun 12 '06 #4

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

Similar topics

2
6183
by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!-- Hide JavaScript from Java-Impaired Browsers function NavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#CC0000";}} function NavRollOut(oTd) {if (!oTd.contains(event.toElement))
4
12737
by: Alexandre Jaquet | last post by:
Hi, I would like to know how can I change a row background color when an user select a row thx
10
2589
by: Harry Haller | last post by:
How can I change the value in a css class? For instance, with I.E., I want to change the value in the class span.arr from middle to 0.2em. The value of middle is OK for most other browsers. I expected the code below to work but I.E. does not like it. What should I be doing?
7
4612
by: News | last post by:
I would like to know how I loop through a html file and validate it is the type of element I am seeking and then change something in the element. IE for(x=0;x<this.document.elements.length;x++) { if(this.element.type= = "<DIV>") { this.element.z-index=1;
1
6772
by: sueian | last post by:
can some1 help with this code. can i add in a function like on click. when user click one of the link. the color will change to static from mouse over color. the text need to highligted after click. thanks <html> <head> <style type="text/css">
7
21823
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
4
2438
by: gregincolumbus | last post by:
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes. Ideally, a change of select1 1. trigger the population of select2 (and set it initially to 0) 2. make the text fields disappear 3. trigger the financial calculation to reflect the select1 choice. Any help would be greatly appeciated !
4
23491
by: TAL651 | last post by:
Hello, Here's the challenge I'm trying to solve: I'd like, when I click a button on a page, that it causes the style for all elements of a certain class to change. When I click the button again, it should change back. Using getElementsById would be inefficient because I don't want to assign a specific ID to every single element on my page. Here's a simplified example: <p class="normal">Here is some text that will not change</p> <p...
15
3731
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it throws error. How I can change the opacity of an element in Firefox.
0
9691
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
9551
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
10505
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
10035
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
9090
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
7580
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
6813
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
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.