Long story short, you can't do what you're trying to do. You have some massive scoping issues. first, anything within you document.ready function (as defined by $(funciton(){..});) that gets declared in there is accessible only inside that function itself.
Now, I'm not sure what you're actually trying to accomplish here, as this example is a bit on the simple side. Could you give a broader idea of your goal? That'd help in putting you on the right direction to the best way to get this done (as if you're merely trying to echo a variable, there's way better implementations than what you've described). On Jun 26, 5:06 am, jasper saronno <jakirihutim...@gmail.com> wrote: > Hello Everybody, > > I am not sure I have explained well enought what I mean. > > I found very difficult to call a method outside his scope. > > For example I have 2 files js > > myFunction.js > > init.js (where I initialize all my page) > > [init.js ] > // JavaScript Document > $(document).ready(function(){ > //call getX(); > > }); > > ----------------------------------------------------- > > [myFunction.js ] > // JavaScript Document > > $( > function(){ > var x = "Hello world"; > function getX(){ > alert(x); > } > } > ); > > I tried many syntax in order to call the method outside its scope > > $.getX(); > > $(function(){getX()}); > > $().function().getX(); > > $("myHtmlObj").click(function(){getX()}); > > I really would like to understand that issue, if you also may suggest > the title of a good book and the chapter that explain it I would > really appreciate. > > Many thanks > - jasper