views:

196

answers:

3

How to call javascript onmouseout event in javascript code?

I.e.:

var div=document.getElementById('new');
if(div.mouseout)
  document.getElementById('new').style.visibility='hidden';

Thanks.

+2  A: 

I think you want:

var div = document.getElementById("new");
div.onmouseout = function (e)
{
    this.style.visibility = "hidden";
}
Andy E
Yeah true i have put an alert inside the loop but it doesnt show up...................
Hulk
It's not a loop, and you'll need to show us your full code if you want us to debug it (edit it into your question).
Max Shawabkeh
i have edited my question.i.e, on mouseout i want to set document.getElementById('new').style.visibility='hidden';
Hulk
@Hulk: See my update.
Andy E
A: 
window.onload = function(){
    var div=document.getElementById('new');
    div.onmouseout = function(){
        this.style.visibility='hidden';
    };
};

You can use this keyword to specify the current element, no need to again fetch the element using document.getElementById.

Working Demo

rahul
Thanks.....................i got it now.
Hulk
A: 
var div = document.getElementById("new");
div.mouseout = function()
{
this.style.display='none';
}
streetparade
Thanks.....................
Hulk