Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a question about function toggle

Status
Not open for further replies.

benluke4

Technical User
Jan 27, 2005
127
0
0
GB
Hi, im really not very clued up with javascript and have managed to put this together with help from the css forum.

Im trying to show and hide a div on mouse over an image and mouse out.

At the moment ive sourced code to get it to show and hide the div onclick but need to achieve sho and hide div on mouse over and mouse out?

any help much appreciated

heres the code i have at the moment

Code:
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function toggle(el)
{
myEl = document.getElementById(el);
myEl.style.display = (myEl.style.display == 'none') ? 'block' : 'none';
}
</script>
</head>
<body>
<div id="show" style="display: block;"><a href="#" onclick="toggle('show');toggle('hide');toggle('a');"><img src="logopoint.gif" width="14" height="17" border="0"></a></div>
<div id="hide" style="display: none;"><a href="#" onclick="toggle('show');toggle('hide');toggle('a');">Close</a></div>
<div id="a" style="display: none;">This is a logo</div>
</body>
</html>

Thanks

Ben
 
Try something like this:

<script type="text/javascript">
function toggle(el)
{
var state = (document.getElementById(el).style.display == 'none') ? 'block' : 'none';

showhide(el, state);
}

function showhide(divname, state)
{
document.getElementById(divname).style.display=state;
}

</script>
</head>
<body>
<div id="show" style="display: block;"><a href="#" onclick="toggle('show');toggle('hide');toggle('a');" [red]onmouseover="showhide('hide', 'block'); return true;" onmouseout="showhide('hide', 'none'); return true;"[/red]><img src="logopoint.gif" width="14" height="17" border="0"></a></div>
<div id="hide" style="display: none;"><a href="#" onclick="toggle('show');toggle('hide');toggle('a');">Close</a></div>
<div id="a" style="display: none;">This is a logo</div>
 
thanks very much that helps loads, i have some more questions but need to work on some things first

thanks

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top