This is the first paragraph.




The Code (fresh off the presses, displaying what was used above):

  Try the code out and play with it on jsFiddle.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script type="text/javascript" src="http://peter-ajtai.com/jquery/jquery-1.4.2.min.js"></script>
  5. </head>
  6. <body>
  7. <div id="container">
  8. <input type="button" value="Click to toggle" /><br/>
  9. <p>This is the first paragraph.</p>
  10. </div>
  11. <script type="text/javascript">
  12. $('input').toggle(
  13. function () {
  14. var content = '<p id="box">' + 'This is the second paragraph' + '</p>';
  15. $("#container").append(content);
  16. },
  17. function () {
  18. $('#box').remove();
  19. }
  20. );
  21. </script>
  22. <br/><br/><br/>
  23. <h2>The Code (fresh off the presses, displaying what was used above):</h2>
  24. <p style="color:green; font-family:sans-serif;">&nbsp;&nbsp;Try the code out and play with it on <a href="http://jsfiddle.net/mjUcR/">jsFiddle</a>.</p>
  25. <?php
  26. include_once "../php/codify-function.php";
  27. // Show code ##################################################################
  28. codify(file_get_contents(__FILE__), 'javascript');
  29. ?>
  30. </body>
  31. </html>