[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread donb
You can't. It exists for the duration of the ready function, then it's gone. On Oct 24, 7:51 pm, Nikola nik.cod...@gmail.com wrote: Hi, I've been trying to understand a little tidbit of jQuery here... Lets say we define an object in the Document ready method: $(function(){         var

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread MorningZ
it's local to that event if you need it globally var pen = {}; $(function(){ pen = { type: Ballpoint, color: blue, hasInk: true } }); would allow you to reference pen from anywhere in your code On Oct 24, 8:01 pm, donb

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread Nikola
It has to be stored somewhere though... Say, for example, we bind a handler to the click event on the BODY of the document and we log the pen object to the console. $(function(){ var pen = { type: Ballpoint, color: blue,

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread Nikola
Right, thanks, I understand how to make it a global but what I'd really like to understand is how to access it within the ready object. On Oct 24, 8:17 pm, MorningZ morni...@gmail.com wrote: it's local to that event if you need it globally var pen = {}; $(function(){         pen = {      

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread Michael Geary
The concept you're looking for is called a closure. Search for: javascript closure and you will find all sorts of information about closures. It really has nothing to do with jQuery or the DOM. Closures are part of the core JavaScript language and work in any environment where JavaScript is

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread Nikola
Thanks Mike, I generally understand closures and your explanation was very good. I think what your saying is that the example pen object is just a local variable to the ready callback. Thanks for clearing that up... On Oct 24, 10:51 pm, Michael Geary m...@mg.to wrote: The concept you're

[jQuery] Re: Variable within document ready... where is it in the DOM?

2009-10-24 Thread Nikola
Actually, thanks to everybody for the replies. I think you were all basically saying the same thing in different ways come to think of it... On Oct 24, 11:30 pm, Nikola nik.cod...@gmail.com wrote: Thanks Mike, I generally understand closures and your explanation was very good. I think what