Monday, December 17, 2012

A JavaScript to toggle HTML content



The following JavaScript function  toggleLayer is used to toggle content in HTML
        <script type="text/javascript" language="javascript">
       
        function toggleLayer(layer) {
          var d = document.getElementById(layer);
          d.style.display = (d.style.display == "") ? "none" : "";
        }
   
        </script>';


Example, when users click the lik Add a comment,  "This is Guesbook between id addToGuestbook
is toggled.

<a href="javascript:toggleLayer('addToGuestbook');">Add a comment</a>

 <div id="addToGuestbook">This is Guestbook</div>

No comments:

Post a Comment