473,387 Members | 1,687 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,387 software developers and data experts.

className change not working : possible Solution

I was just battling a small dHTML quirk where I was attempting to set
the className attribute of option elements, but it didn't seem to be
updating. I did some testing with other elements and came to find the
problem was not in my code at all, but rather in my logic...

I had a dehighlightAll(selectBox) function in my code library and
decided to use this to reset all the options to white backgrounds.
This worked fine with my previous method where I explicitly set the
style.background attribute of the options. But when I wanted to use
className instead, everything mysteriously stopped working. I thought
there must be something wrong with className and started
investigating....

I eventually came to the realization that if you explicitly set a style
element, it won't be overridden by the className. This was an
oversight on my part and thought that it might be useful to post about
it, because it could be easy to miss and I haven't seen any posts about
it.

It really comes down to the CSS order of precedence ... that is the
style field modifies the inline style of the object, while the
className references a class ... and as CSS precedence dictates, inline
styles override all others. So this is a word to the wise to be
careful if you're ever mixing className and style elements :)

May 29 '06 #1
1 3587
Supernaut wrote:
I eventually came to the realization that if you explicitly set a style
element,
You cannot "set" a style element. See below.
[...]
It really comes down to the CSS order of precedence ... that is the
style field
You are speaking of a proprietary property, or a standardized attribute;
not a field.
modifies the inline style of the object, while the className references
a class ... and as CSS precedence dictates, inline styles override all
others.
"Precedence" is a wrong/insufficient term here.

<URL:http://www.w3.org/TR/CSS2/cascade.html#specificity>
<URL:http://www.w3.org/TR/CSS21/cascade.html#specificity>

Since CSS2 and CSS 2.1 differ here, the latter is to be
considered the erratum for the former, even if it is a WD.
So this is a word to the wise to be careful if you're ever mixing
className and style elements :)


You mean the `style' attribute (style="...") or `style' property
(...style.foo = bar), not the style element (<style ...>...</style>).
PointedEars
--
There are two possibilities: Either we are alone in the
universe or we are not. Both are equally terrifying.
-- Arthur C. Clarke
May 29 '06 #2

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

Similar topics

7
by: Joshua Beall | last post by:
Hi All, I have been trying to dynamically call a static member function, as follows: $className = 'MyClass'; $methodName = 'MyMethod' $result = $className::$methodName(); However, I get a...
12
by: techie | last post by:
Hi All, I have a portal working on an intranet for a company. The portal was designed keeping in mind the resolution of 1024*768. I am including a ..css file in all the files. Now i have to make...
1
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC {...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
2
by: CaptainKS | last post by:
Has anyone ever been able to change the classname for a C# (or even VB.NET) standalone app? Using Spy, I can see that the classname .NET gives the app is "WindowsForms10.Window.8.app*", but I...
19
by: felixnielsen | last post by:
Some might remember that i, not so long ago, started a treath or two about a weird 3d labyrinth. I now have a working code, that i want to share, hear comments, advice, ect., but first let me...
2
by: torbs | last post by:
Hi I have two quicktime players. I load them like this: <object id="'movie" class="synligActiveXSpille" (...) <embed name="movie class="SynligSpiller (...) References to the two players are...
1
Tarantulus
by: Tarantulus | last post by:
Hi guys, I have the following simple function which errors in IE6 function changecss(id,class){ document.getElementById(id).className = class; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.