@supercainauthorJul 26.2006 — #thanks guys. But isnt that code to change the class of an object when hovering the SAME object? what im trying to do is to have an object that when is mouseovered change the class of a DIFFERENT object. Or is the same code for both?
@supercainauthorJul 26.2006 — #sorry, one more question. Sorry if i sound too annoying. With your code (excellent by the way), when you hover the link actually the object in question doesnt change class at that moment but after you mouseout the link. Also the object remains switched to the new class until you hover the link again. Any modification possible to make:
1. the class of the object change AT the moment you hover the link, and
2. that the object returns to its original class once you mouseout the link.
I know it sounds annoying but thats the only thing i would need to have this working perfectly.
<div onmous[U]e[/U]over="javascript:changeClass('myDiv')" onmouseout="javascript:changeClass('myDiv')">change class for myDiv element</div>
...
<div id="myDiv" class="defaultClass">mydiv</div>[/B][/QUOTE] Yeap, mistyped that "e"
On the other hand, no, there is no need to use [B]javascript:[/B] "pre-code". It is to be used only when substitutes a HTML action, for instance:
<a href="javascript:void(somefunction())">
...which is not quite a good method, as it is better to leave a link out there for people with javascript disabled, and use rather [B]onclick[/B] event, ended with a [B]return false[/B] along.
So that:
<i> </i><script type="text/javascript"> function changeClass(id){ var obj = document.getElementById(id); obj.className=obj.className=='defaultClass'?'newClass':'defaultClass'; } </script>
<div onmouseover="changeClass('myDiv')" onmouseout="changeClass('myDiv')">change class for myDiv element</div> ... <div id="myDiv" class="defaultClass">mydiv</div>
<div onmouseover="changeClass('myDiv')">change class for myDiv element</div> ... <div id="myDiv" class="defaultClass">mydiv</div>
@supercainauthorJul 27.2006 — #hmm im afraid to say it didnt work. Now it changes class once and it doesnt return to its original state even if you mouseout the link.
Im stating what value is for each variable, so we can prevent any confusions
<i> </i><script type="text/javascript"> function changeClass(img1) { var obj = document.getElementById(img1); obj.className='opacity2'; obj.onmouseout = function(){this.className='opacity1';} } </script>