Javascript function inside document.ready

javascript, jquery, jsp

Solution

Because it's not available in the global scope. Any function defined within the anonymous function you pass as an argument to `$.ready()` is only available within that function.

To achieve what you want to do you need something like:

$(document).ready(function(){
     function abc() {}

     $('#a').on('click',abc);
});

For more information on function scope see this MDN article

Problem

Why doesn't any javascript function written inside document.ready be directly called from an event in jsp? Eg: ``` $(document).ready(function(){ function abc() { //Some stuff here } }); ``` From something like: ``` <input id="a" type="button" onclick="abc();"> ```

Original source

Related problems