I have a problem with the mouseover event. When I hover over one of the divs the color on the div (home) just changes perfectly fine, but when I hover over the other div (test) that one will turn as well to the same color so I will have two divs with the same color at the same time.
How i would like it is that if you go to another div the mouseover will go away from the old div it was on. So only one div at a time can have the mousover event. I am quite new to JS, it would be amazing if anyone could help me through this! :-)
Here is my code:
HTML
<li class="first" id="color"><a href="index.php">Home</a></li> <li id="color1" ><a href="index.php?content=test">test</a></li> JavaScript
var div = document.getElementById( 'color' ); div.onmouseover = function() { this.style.backgroundColor = 'red'; } var div = document.getElementById( 'color1' ); div.onmouseover = function() { this.style.backgroundColor = 'red'; }
mouseoutormouseleave, but that doesn't seem to be what you're asking for. You don't want the color to change until you enter a different div, right? Or do you actually want the red to go away as soon as you leave the div?