Created
November 4, 2012 20:16
-
-
Save apphp-snippets/4013487 to your computer and use it in GitHub Desktop.
This function allows you to pass two variables that represent ID of two elements on your page. What you click on one of them it hide it and shows another one.
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
| <script type="text/javascript"> | |
| /* Source: http://www.apphp.com/index.php?snippet=javascript-toggle-elements */ | |
| function toggle(id, id2){ | |
| var toggle_one = document.getElementById(id); | |
| var toggle_two = document.getElementById(id2); | |
| if(toggle_one.style.display == "block"){ | |
| toggle_one.style.display = "none"; | |
| toggle_two.innerHTML = "Show"; | |
| }else{ | |
| toggle_one.style.display = "block"; | |
| toggle_two.innerHTML = "Hide"; | |
| } | |
| } | |
| </script> | |
| <a href="#" id="tlink" onclick="toggle('comments', 'tlink');">Show</a> Comments<br><br> | |
| <div id="comments" style="display:none;padding 10px;">Now you can see the comments</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment