473,511 Members | 16,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating CSS class

Hi!

I want to directly manipulate a CSS class:

#bla
{
property: 123;
}

<span id="bla">foo</span>
<span id="bla">bar</span>

Both spans shall change when doing something like:

bla.property=321
Is this possible?

Timo
Jul 23 '05 #1
1 1135
On Fri, 09 Apr 2004 19:54:03 +0200, Timo Nentwig <tc*@spamgourmet.org>
wrote:
I want to directly manipulate a CSS class:

#bla
{
property: 123;
}
That's actually a CSS declaration block which uses an ID selector. There's
nothing relating to classes there.
<span id="bla">foo</span>
<span id="bla">bar</span>
That's invalid HTML. The id attribute is supposed to uniquely identify an
element thoughout the entire document. You cannot do that if two values
are the same. What you're trying to do would be better acheived with:

<span class="bla">foo</span>
<span class="bla">bar</span>
Both spans shall change when doing something like:

bla.property=321

Is this possible?


In some browsers, yes. It requires support for the document.styleSheets
property. From there, you can find the style sheet that contains the
declaration and modify it.

function modifyRule( selector, property, value )
{
if( document.styleSheets )
{
var sS = document.styleSheets, s = null;

for( var i = 0, n = sS.length; i < n; ++i )
{
if(( s = sS[ i ]) && !s.disabled && s.cssRules )
{
var cR = s.cssRules, d;

for( var j = 0, m = cR.length; j < m; ++j )
{
if(( 1 == cR[ j ].type ) &&
( selector == cR[ j ].selectorText ) &&
( d = cR[ j ].style ))
{
if( d.getPropertyValue && d.setProperty &&
( null != d.getPropertyValue( property ))
{
d.setProperty( property, value, '' );
return true;
}
}
}
}
}
}
return false;
}

The function above is untested, but it should work in theory. If the
property value was set, the function will return true. If the function
fails, for any reason, it will return false.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

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

Similar topics

4
22928
by: Michael J. Astrauskas | last post by:
Does anyone have a function for manipulating GET variables in a URL? I want to be able to modify some parameters without affecting others. An example of what I'm looking for: Let's say the...
2
2096
by: Ido Flatow | last post by:
Hi all, I've been exploring the way I can manipulate WSDL.exe using SchemaImporterExtension in order to create a proxy to my liking. My situation is as follows - I have a web site that has...
2
1394
by: Gary Wessle | last post by:
Hi Stroustrup p.312 second paragraph after the code. " To get polymorphic behavior in C++, the member function called must be virtual and objects must be manipulated through pointers or...
4
2480
by: raknin | last post by:
Hi, I built a form in php that contains some check boxes and drop-down boxes and a Add button. What I want to do is manipulating the check box state (checked and uncheked state) in order to...
4
1603
by: Wilbert Berendsen | last post by:
Hi, is it possible to manipulate class attributes from within a decorator while the class is being defined? I want to register methods with some additional values in a class attribute. But I...
0
7245
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,...
0
7144
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...
0
7427
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...
1
7085
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
7512
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
5671
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,...
0
4741
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
3227
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
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.