Show the ID of the LI clicked

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

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Binding events</title>
  5. <script type="text/javascript" src="http://peter-ajtai.com/jquery/jquery-1.4.2.min.js"></script>
  6. <meta charset="utf-8" />
  7. <script type="text/javascript">
  8. // When the page is ready ==================================================
  9. $(document).ready(function()
  10. {
  11. $('li').each(function(index)
  12. {
  13. $(this).click( function() { alert("This would trigger => tag_search(" + $(this).attr('id') + ")")});
  14. });
  15. });
  16. </script>
  17. </head>
  18. <body>
  19. Show the ID of the LI clicked
  20. <ul>
  21. <li id="Roger"><a href="#">zero</a></li>
  22. <li id="Dodger"><a href="#">one</a></li>
  23. <li id="23884"><a href="#">two</a></li>
  24. <li id="Fubar"><a href="#">three</a></li>
  25. <li id="Gungho"><a href="#">four</a></li>
  26. <li id="Burlap"><a href="#">five</a></li>
  27. </ul>
  28. <h2>The Code (fresh off the presses, displaying what was used above):</h2>
  29. <?php
  30. include_once "../php/codify-function.php";
  31. // Show code ##################################################################
  32. codify(file_get_contents(__FILE__), 'html4strict');
  33. ?>
  34. </body>
  35. </html>