Re: Use a style in onmouseover? by mayayana
mayayana
Mon May 14 09:23:18 CDT 2007
> In my case, I have nested DIVs and the mouseover/out event never triggers.
>
> THis is similar to the other issue I had with the context menu where we
> needed "parent." in front of the call in order for it to work.
>
That looks like it could be quite a can of worms.
If you've got DIVs within DIVs, and SPANs within
those, you'll just have to test them to see what IE
thinks you're hovering over. I've never tried such
extensive hovering code, and SPAN and DIV are
not really meant for that kind of usage, so it might
get tricky. If you can't get the formatting tags to work
right you might try a table inside the DIV; then code
to the TD.
In the case you posted, you're writing the sub for the
class:
Sub divGR_onmouseout()
But VBS knows nothing about your CSS designations.
You need to use the ID for that. Your ID is here:
<DIV ID="SC1" Class="divGR">
So the sub needs to be:
Sub SC1_onmouseout()
Otherwise, what's the ID for? Why did you give
an ID to each DIV if it's not serving any purpose?
Nothing has to have an ID. It's only of value if you're
going to use it for scripting. It's kind of confusing, though,
because the design of this stuff was not very well
thought out, in many cases.
ID can actually be for scripting *and/or* for specific
CSS designations using #. In other words, ID is a unique
ID for any purposes where that's needed. You can use
something like:
<Style>
#SC1 {color: #000000;}
</style>
That will set the style for the element that has ID of
"SC1". In that case you can use the same ID in
your script sub. But ID is not often relevant in CSS
because it's intended to be used on a single, unique
element. Usually you'd be using classes to set your
graphical style and then IDs to script dynamic changes
to specific elements.
Class is *only* for CSS. So you don't use that in script.
(As Evertjian pointed out, there is an IE DOM property
className, but I can't think of a case where that would
be useful, since className would be used to change
or retrieve the class of an element. If you find yourself
doing that then you're probably in a real mess. CSS and
script are confusing and complex enough already without
blending them into a changing landscape. :)
If I may say so, I think you need to study both script
and CSS. You seem to be trying to learn by rote, copying
code that you hope will work. But the result is that you're
running into a lot of problems because of javascript
accidentally mixed with VBS, CSS accidentally blended
with script, etc.