views:

186

answers:

3

Should be super simple for you guys...div one gets clicked, div two appears. What I don't know how to do is make div 2 go away when div one is clicked again.

<img src="/..." width="" height"" onClick="MM_showHideLayers('logo','','show','logoEasterEgg','',show')">

What should I add to this line of code to make the div 'logoEasterEgg' disappear when the image in div 1 is clicked again?

A: 
Andrew Hare
+3  A: 

You could do something similar to what was suggested in response to this question with jQuery.

Basically just have a class for the div which you add and remove based on whether it is already there.

YonahW
jQuery has a toggle function $('#div1').toggle(function() { $('#logoEasterEgg').show(); }, function() { $('#logoEasterEgg').hide(); });
bendewey
thanks for this great tip. this will definitely come in handy
YonahW
A: 

Instead of using MM_showHideLayers() could you do something like this...?

function toggleDiv(divId)
{
  var myDiv = document.getElementById(divId);
  if (myDiv) 
  {
    if (myDiv.style.display === 'none') 
    {
      myDiv.style.display = 'block';
    }
    else
    {
      myDiv.style.display = 'none';
    }
  }
}

<img src="/..." width="" height"" onClick="toggleDiv('logoEasterEgg')">
Jeremy Bade