Title / Description
Code <head> ..... <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> function updateToggleText() { if ($("#navigation").is(":visible") == true) { $("#toggle").text("Hide Navigation"); } else { $("#toggle").text("Show Navigation"); } } $(document).ready(function() { $("#toggle").click(function() { $.post({url: "/toggle-me-baby", function(response) { if (response == 'toggled!') { $("#navigation").toggle(); updateToggleText(); } else { alert("There was a problem toggling the navigation!"); } }); }); }); </script> ....... </head> <!-- Replacing the code from above --> <% if navigation_should_be_shown? %> <div id="navigation"> <!-- Some links and stuff --> </div> <a id="toggle" href="/toggle-me-baby">Hide Navigation</a> <% else %> <div id="navigation" style="display:none"> <!-- Some links and stuff --> </div> <a id="toggle" href="/toggle-me-baby">Show Navigation</a> <% end %>
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code