Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Jquery modifying the click function of a button .
  2. $("button").click() instead of standard  $("button").click(function(){
  3.        
  4. <html>
  5. <head>
  6.  
  7. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" >
  8.  </script>
  9. <script type="text/javascript">
  10. $(document).ready(function(){
  11.   $("button").click()
  12. {
  13.    callMe();
  14.  
  15. }
  16. });
  17.  
  18. function callMe()
  19. {
  20.  $("p").hide();
  21. }
  22. </script>
  23. </head>
  24.  
  25. <body>
  26. <h2>This is a heading</h2>
  27. <p>This is a paragraph.</p>
  28. <p>This is another paragraph.</p>
  29. <button>Click me</button>
  30. </body>
  31. </html>
  32.        
  33. $("button").click()
  34. {
  35.    callMe();
  36. }
  37.        
  38. $("button").click(function()
  39. {
  40.    callMe();
  41. });
  42.        
  43. var myFunction = function()
  44. {
  45.    callMe();
  46. };
  47. $("button").click(myFunction);
  48.        
  49. function myFunction()
  50. {
  51.    callMe();
  52. }
  53. $("button").click(myFunction);
  54.        
  55. function callMe()
  56. {
  57.  $("p").hide();
  58. }
  59.  
  60.  
  61. $(function(){
  62.   $("button").click(callMe)// just provide the reference to call me
  63. });