473,503 Members | 11,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using JavaScript to rewrite CSS rules

jbj
I am trying to make a javascript function that can rewrite javascript
rules dynamically (no, not the style tag of an individual element, but
the actual rule in the <head> portion of the document).

I have this code working in Mozilla (so I imagine Netscape browsers)
but it gives me an error with IE. A few questions about it:

First, here is my current code:
<code>
function expand(show)
{
for(var i=1;i<=linkNum;i++)
{
if(show == i)) document.styleSheets[0].cssRules[i].style.visibility="visible";
else document.styleSheets[0].cssRules[i].style.visibility="hidden";
}
}
</code>

As I said, this works in Moz, but not in IE. How do i handle this??

And my next question, instead of having to access each rule by its
index in an array of the stylesheet, is there a way I can access it by
name (so instead of doing cssRules[0], i could do.Rule("body") or
something with a similar function?)

I am trying to do some work with more advanced DHTML and am running
into even more IE specfic code it seems. Thanks for the help.
Jul 23 '05 #1
1 3968


jbj wrote:
I am trying to make a javascript function that can rewrite javascript
rules dynamically (no, not the style tag of an individual element, but
the actual rule in the <head> portion of the document).

I have this code working in Mozilla (so I imagine Netscape browsers)
but it gives me an error with IE. A few questions about it:

First, here is my current code:
<code>
function expand(show)
{
for(var i=1;i<=linkNum;i++)
{
if(show == i)) document.styleSheets[0].cssRules[i].style.visibility="visible";
else document.styleSheets[0].cssRules[i].style.visibility="hidden";
}
}
</code>

As I said, this works in Moz, but not in IE. How do i handle this??
IE has its own API, with IE you need e.g.
document.styleSheets[0].rules[1].style.cssPropertyName = ...
And my next question, instead of having to access each rule by its
index in an array of the stylesheet, is there a way I can access it by
name (so instead of doing cssRules[0], i could do.Rule("body") or
something with a similar function?)


You can check the selectorText property of a rule.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

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

Similar topics

15
2189
by: Davide R. | last post by:
Ciao a tutti, vi spiego il mio problema Ho una pagina HTML che referenzia un CSS esterno. Ho alcuni elementi HTML che appartengolo ad una classe (chiamiamola "class1"). Avrei la necessità,...
3
26491
by: Noozer | last post by:
I have several tags on a webpage of the same class. If the user clicks a specific checkbox I'd like to be able to alter the display property of the class, affecting all objects of that class. ...
0
1938
by: Netveloper | last post by:
Hi, I'm playing around with url rewriting and I have come across a problem which I can't seem to get past. The general ide is to have a IHttpHandlerFactory class which checks the incoming...
18
3208
by: Aaron Gray | last post by:
Hi, I have a single line of CSS that I want to do via JavaScript :- p { margin: 0px; } How do I go about this ? Many thanks in advance,
14
1800
by: Stan Canepa | last post by:
This post is mostly for discussion. Why rewrite in .NET? Just a general discussion not related to any specific details. I was just looking to see what reasons developers are looking to, to help...
10
1929
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
1
1961
by: JumpingOffPlace | last post by:
Hi, I'm hoping that the wealth of knowledge here can stop me from spinning my wheels on this syntax error for hours. :) Below is the code, and the error I am recieving.... Code: <!DOCTYPE...
10
6050
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
6
2571
by: Aaron Gray | last post by:
Hi, Is there any tool that will concatinate JavaScript files compacting them spacewise and removing comment fields ? I have some sed script that sort of does the job but was wondering if there...
1
7015
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...
0
7470
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...
0
5602
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,...
1
5026
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...
0
4693
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...
0
3183
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...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
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...

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.