473,659 Members | 2,920 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.styleS heets[0].cssRules[i].style.visibili ty="visible";
else document.styleS heets[0].cssRules[i].style.visibili ty="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 3982


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.styleS heets[0].cssRules[i].style.visibili ty="visible";
else document.styleS heets[0].cssRules[i].style.visibili ty="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.styleS heets[0].rules[1].style.cssPrope rtyName = ...
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
2210
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à, alla pressione di un tasto di lanciare un javascript che mi cambia un attributo della classe "class1" (per esempio 'font-size', ma potrebbe essere qualsiasi altro attributo). Teoricamente potrei fare un loop in tutti gli elementi della pagina e
3
26499
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. This is an intranet application so we know that javascript will be enabled and the browser will be IE. How can I affect all the members of this class? Is there a way I can toggle the DISPLAY property of a class so all the elements using that class...
0
1947
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 request url against a set of predefined rules and creates and return the appropriate IHttpHandler implementation. Inside the IHttpHandler implementations, the request is examined and
18
3214
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
1812
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 decide whether they should rewrite their app in .NET. What are the trends being observed of Microsoft when it comes to .Net? How much longer will COM objects live on? How stable is the Framework?
10
1951
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, CN) Dim DR As OleDbDataReader = CMD.ExecuteReader()
1
1977
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 HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@ taglib uri="/WEB-INF/tag-lib/struts-html-el.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tag-lib/struts-bean.tld" prefix="bean" %>
10
6074
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
6
2579
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 were any hopefully open source tools that will do the job. I don't want encryption or obverscation though.
0
8428
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
8335
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
8627
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...
1
6179
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
5649
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
4175
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...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.