3

I have a script that makes the element display = block using onmouseover

<script language="JavaScript">
function aaa() 
{
    document.getElementById('cat').style.display = "block";
}
</script>

<a href='#' onmouseover='aaa()'>hover on me</a>

<div  id='cat' style='display:none;'>this will show</div>

I wanted to return that element back to it's original display properties (none) when the mouse isn't over the

"<a href='#' onmouseover='aaa()'>hover on me</a>"

how can I do this?

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
Sam San
  • 6,567
  • 8
  • 33
  • 51

5 Answers5

7

There's the onmouseout event

function bbb() 
{
    document.getElementById('cat').style.display = "none";
}

...

<a href='#' onmouseover='aaa()' onmouseout='bbb()'>hover on me</a>
Jcl
  • 27,696
  • 5
  • 61
  • 92
3

Demo: http://jsfiddle.net/TRxRV/1/

HTML:

<a href='#' onmouseover='show();' onmouseout='hide();'>hover</a>
<div  id='cat' style='display:none;'>cat</div>​

JavaScript:

window.show = function () {
    document.getElementById('cat').style.display = "block";
}

window.hide = function () {
    document.getElementById('cat').style.display = "none";
}
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
3

This should help you...

                function aaa()
                {
                    document.getElementById('cat').style.display = "block";
                }
                function bbb()
                {
                    document.getElementById('cat').style.display = "none";
                }

        <a href='#' onmouseover='aaa()' onmouseout="bbb();">hover on me</a>
        <div id='cat' style='display: none;'>this will show</div>
Nikhil D
  • 2,479
  • 3
  • 21
  • 41
3

i am considering the same code u provided as example. If u include the original display properties within the onMouseout() Function U will get back to the original properties when the mouse is not over.

<script language="JavaScript">
function aaa() 
{
    document.getElementById('cat').style.display = "block";
}
function bbb()
{
//include the code TO CHAGE THE PROPERTY HERE
document.getElementById('cat').style.display = "      ";
}
</script>

<a href='#' onmouseover='aaa();' onmouseout="bbb();">hover on me</a>

<div  id='cat' style='display:none;'>this will show</div>
Praveen Singh
  • 534
  • 2
  • 8
  • 23
2

You should use onMouseOut event for that, code will look like

<a href='#' onmouseover='show();' onmouseout='dontShow();'>hover</a>
<div  id='cat' style='display:none;'>this will show</div>​



function show() {
    document.getElementById('cat').style.display = "block";
}

function dontShow() {
    document.getElementById('cat').style.display = "none";
}
NoNaMe
  • 6,020
  • 30
  • 82
  • 110