Posted By

ptlrikin on 08/07/12


Tagged

javascript


Versions (?)

Hide Content


 / Published in: JavaScript
 

The following code can be used to hide content or it's great for FAQ section. Note - the script goes in the head and the list goes in the body.

  1. <script language="javascript">
  2. function togglediv(divid){
  3. if(document.getElementById(divid).style.display == 'none'){
  4. document.getElementById(divid).style.display = 'block';
  5. }else{
  6. document.getElementById(divid).style.display = 'none';
  7. }
  8. }
  9. </script>
  10.  
  11. <!-- The following list codes goes in the body where you want the content -->
  12. <ul>
  13. <li>
  14. <a href="javascript:;" onclick="togglediv('tag1');">Title Goes Here</a>
  15. <div id="tag1" style="padding-top: 5px; margin-top: 5px; padding-bottom: 10px; margin-bottom: 10px; border-bottom-color: #cccccc; border-bottom-width: 1px; border-bottom-style: solid; display: none;">
  16. <p>Content goes in here.</p>
  17. </div>
  18. </li>
  19. </ul>

Report this snippet  

You need to login to post a comment.