473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

stylesheets minipulation - Question: How to change a string to a property name.

Jezternz
145 100+
OK.
I have made a function here that will suposedly go down the stylesheet and change particular properties. However I want to be able to make the property name defined when the function is called.

Function:
Expand|Select|Wrap|Line Numbers
  1. function changeRule(theNumber, property, value) {
  2.     var theRules = new Array();
  3.     if (document.styleSheets[0].cssRules) {
  4.         theRules = document.styleSheets[0].cssRules;
  5.     } else if (document.styleSheets[0].rules) {
  6.         theRules = document.styleSheets[0].rules;
  7.     }
  8.  
  9.     theRules[theNumber].style.[property] = value;
  10. }
  11.  
Basic Function call:
Expand|Select|Wrap|Line Numbers
  1. changeRule(1, 'backgroundImage', 'url(./images/corner2.gif)');
  2.  
so basicly I want the "property" variable to apear as the propertyname. How can i do this? any other suggestions to improve this code?
Jan 11 '08 #1
2 1353
Logician
210 100+
Expand|Select|Wrap|Line Numbers
  1. var theRules = new Array();
  2.  
It's already an array so don't need that.
Expand|Select|Wrap|Line Numbers
  1.     if (document.styleSheets[0].cssRules) 
  2.  
Don't blindly assume that document.styleSheets is supported
Expand|Select|Wrap|Line Numbers
  1.     theRules[theNumber].style.[property] = value;
  2.  
theRules[theNumber].style[property] = value;


Expand|Select|Wrap|Line Numbers
  1. function changeRule(theNumber, property, value)
  2. {
  3.   var theRules, ss=document.styleSheets||null;
  4.  
  5.   if(ss && ss.length)
  6.   {
  7.    ss=ss[0]; 
  8.    if( theNumber < (theRules=ss.rules||ss.cssRules).length)
  9.     theRules[theNumber].style[property] = value; 
  10.   }
  11. }
Jan 12 '08 #2
Jezternz
145 100+
ok thanks heaps man. Much apreciated. Can I ask if there is an alternative to stylsheets? This method seems very bitsy, I would like a cleaner script or is this not possible with todays browsers.

By the way the whole reason I am using style sheets is because I want to change the properties of elements like follows .class #id ellement{} eg .big #bigger h1{}
and u cant do this using the standard getelementbyid.
So if theres anotehr way, please tell me :).

Thanks again, Josh
Jan 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
6
by: amethyste | last post by:
hello, This is my sample (simplified): public class Binom { public string _Value;
3
by: Ken H | last post by:
Hi I have a question about architecting solutions.. I have a part of a project which requires me to track person details (name, addresses, etc... Should I be creating Person objects, Address...
1
by: Chad | last post by:
2131 Public Property ContactId() As SqlInt32 2132 Get 2133 Return MyBase.SqlInt32Property("ContactId") 2134 End Get 2135 ...
3
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
0
by: RSH | last post by:
I am rather new to delegates and I was working through an exersize. I have created a simple commandline project that basically adds or edits customers. I am using two delegates, one to Notify...
4
by: RSH | last post by:
Hi, I have been construction a sample application to further my growth in applying OOP concepts in .Net. My code is structured like this: Person |-- Employee |--- Customer
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.