Toggling Elements with JavaScript

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.

[View All Snippets]
Show Plain Text »
  1. <script type="text/javascript">
  2. function toggle(id, id2){  
  3.     var toggle_one = document.getElementById(id);  
  4.     var toggle_two = document.getElementById(id2);  
  5.     if( == "block"){  
  6. = "none";  
  7.         toggle_two.innerHTML = "Show";  
  8.     }else{  
  9. = "block";  
  10.         toggle_two.innerHTML = "Hide";  
  11.     }  
  12. }
  13. </script>
  15. <a href="#" id="tlink" onclick="toggle('comments', 'tlink');">Show</a> Comments<br><br>  
  16. <div id="comments" style="display:none;padding 10px;">Now you can see the comments</div>
Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory

Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.