Created
May 16, 2014 22:06
-
-
Save sethmcl/030f4182c1ccfbe5d0db to your computer and use it in GitHub Desktop.
Sample show/hide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Sample page</title> | |
| <meta charset="utf-8"> | |
| <link rel="stylesheet" type="text/css" href="main.css"> | |
| </head> | |
| <body> | |
| <ul id="list"> | |
| <li>Maine</li> | |
| <li>California</li> | |
| <li>Washington</li> | |
| </ul> | |
| <ul id="descriptions"> | |
| <li class="maine"> | |
| <ul> | |
| <li>Description</li> | |
| <li>Command</li> | |
| </ul> | |
| </li> | |
| <li class="california">Description for California</li> | |
| <li class="washington">Description for Washington</li> | |
| </ul> | |
| <script src="main.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #descriptions { | |
| list-style-type: none; | |
| display: block; | |
| width: 500px; | |
| height: 300px; | |
| padding: 0; | |
| margin: 0; | |
| } | |
| #descriptions li { | |
| background: silver; | |
| font-size: 30px; | |
| } | |
| #descriptions li ul li { | |
| width: 40%; | |
| border: 2px solid red; | |
| display: inline-block; | |
| } | |
| #descriptions.show-maine .maine { | |
| display: block; | |
| } | |
| #descriptions.show-california .california { | |
| display: block; | |
| } | |
| #descriptions.show-washington .washington { | |
| display: block; | |
| } | |
| .maine, .california, .washington { | |
| display: none; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var list = document.querySelector('#list'); | |
| var desc = document.querySelector('#descriptions'); | |
| list.addEventListener('click', function (e) { | |
| var state = e.target.innerText.toLowerCase(); | |
| desc.className = 'show-' + state; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment