mardi 7 juillet 2015

If This is Clicked Show This Else Hide This

I have seen other if else examples on here but nothing specifically addressing jquery "if clicked show this else hide this". Here's a simple code example. I would like to know the cleanest way to show the .redStuff when #red is clicked else hide it and show the other classes when the relative id is clicked. Here is the HTML:

<ul id="color">
  <li id="red"><a href="#">Red</a></li>
  <li id="blue"><a href="#">Blue</a></li>
  <li id="green"><a href="#">Green</a></li>
</ul>

<div class="redStuff">Red Stuff</div>
<div class="blueStuff">Blue Stuff</div>
<div class="greenStuff">Green Stuff</div>

and the CSS:

.redStuff, .blueStuff, .greenStuff {
  display: none;
}

Aucun commentaire:

Enregistrer un commentaire