Forum Moderators: open

Message Too Old, No Replies

Change pseudo-class of different element onmouseover?

         

JAB Creations

9:43 am on Jan 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Goal: Avoid the laziness of creating a hover class when we already have a hover pseudo-class (why have two classes when one should work?)

I'm not sure how different the JavaScript will appear but this script simply changes the class. I want to specifically change the pseudo-class. So I want to ultimately change the script from changing the class to "menuh" and instead have it change it to "menu:hover". We are of course changing the hover state of the first element while hovering over the second and they are not nested in any way.

- John

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Change pseudo-class of different element onmouseover</title>
<script type="text/javascript">
//<![CDATA[
function change(id, newClass)
{
identity=document.getElementById(id);
identity.className=newClass;
}
//]]>
</script>
<style type="text/css">
div.menu {
background: #aaa;
color: #000;
}
div.menuh {
background: #f0f;
color: #000;
}
div.menu:hover {
background: #000;
color: #fff;
}
</style>
</head>
<body>

<div class="menu" id="menu1">Menu 1</div>

<div onmouseover="change('menu1', 'menuh');" onmouseout="change('menu1', 'menu');">onmouseover here</div>

</body>
</html>

JAB Creations

7:16 am on Jan 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A shamless bump. :)

Rambo Tribble

1:25 am on Jan 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pseudo-classes are generally tied to events and unless the event is realized, I don't believe there is any way to "fool" the browser into thinking it has. You cannot cause, for instance, window.onload to fire through a script; the event must occur for the handler to be activated.