Div tags - on / off

Must be super easy for you guys ... div one clicked, div two appears. What I don't know how to do is make div 2 go away when the div button 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 "logoEasterEgg" div disappear when the image in div 1 is clicked again?

0


source to share


3 answers


You can do something similar to what was suggested in the answer to this question with jQuery.



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

+3


source


You will need to add another function call to hide the other div after the first call to show it.

The onclick attribute will look something like this:

MM_showHideLayers ('logo', '', 'show', 'logoEasterEgg', '', show '); hide_function ();

The onclick attribute will allow you to use as much javascript as you like, you can overlay as many functions as you like - just don't forget about your semicolons.



Edit:

After reading a little about MM_showHideLayers

, I think you need to change the function to close the div that needs to be closed. In other words, if you want to close logo

then create an onclick attribute (note the hide ):

MM_showHideLayers ('logo', '', ' hide ', 'logoEasterEgg', '', show ');

0


source


Instead of using MM_showHideLayers (), you could 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')">

      

0


source







All Articles