Define functions in jQuery's document.ready() - Javascript jQuery

Javascript examples for jQuery:Document

Description

Define functions in jQuery's document.ready()

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> 
      <script>
var foo;                           // Here's the difference
$(document).ready(function(){
  foo = function ()// w  ww. j a v  a 2  s. c  o  m
  {
    console.log('Bar');
  }
});

      </script>
   </head>
   <body> 
      <input type="button" onclick="foo()" value="Click me"> 
   </body>
</html>

Related Tutorials