[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Joel Birch


On 16/04/2007, at 7:36 PM, fambizzari wrote:

However, I am trying to add an additional $(document).ready(function()
{}); in the middle of the document (i.e. inline) but it is not working
and i don't know why.


Does it work if you move the inline $(document).ready(function(){});  
into the head element? I can't think of a situation where you would  
need it in the body, but I could be wrong. You can have as many $ 
(document).ready(function(){});s as you want so I'd say your problem  
must have to do with having it inline.


Joel.


[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread [EMAIL PROTECTED]

Thanks for the help.

Moving into the head does work, but keeping it inline doesn't.

Can jQuery be used inline?

Fam

Joel Birch wrote:



On 16/04/2007, at 7:36 PM, fambizzari wrote:


However, I am trying to add an additional $(document).ready(function()
{}); in the middle of the document (i.e. inline) but it is not working
and i don't know why.



Does it work if you move the inline $(document).ready(function(){});  
into the head element? I can't think of a situation where you would  
need it in the body, but I could be wrong. You can have as many $ 
(document).ready(function(){});s as you want so I'd say your problem  
must have to do with having it inline.


Joel.



.



[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Joel Birch


On 16/04/2007, at 8:58 PM, [EMAIL PROTECTED] wrote:

Can jQuery be used inline?


jQuery can be used inline (maybe not the 'document ready' function it  
seems though). However, one of the cool things about jQuery is that  
due to the strength of its selector engine (using CSS to target  
elements etc.) it is easy to use unobtrusive javascript which  
provides many benefits over inline javascript and is worth getting  
into the habit of doing by default.


Have fun.

Joel.


[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Andy Matthews
You should be able to use jQuery inline, but you might want to ask yourself
WHY you want to use it inline. The power of jQuery is that it can affect
EVERY part of the document from just one spot. I'd recommend rethinking your
code so as to remove the need for inline JS.
 

  _  

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Monday, April 16, 2007 5:59 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: New to jQuery and struggling


Thanks for the help.

Moving into the head does work, but keeping it inline doesn't.

Can jQuery be used inline? 

Fam

Joel Birch wrote: 


On 16/04/2007, at 7:36 PM, fambizzari wrote: 


However, I am trying to add an additional $(document).ready(function() 
{}); in the middle of the document (i.e. inline) but it is not working 
and i don't know why. 



Does it work if you move the inline $(document).ready(function(){});  into
the head element? I can't think of a situation where you would  need it in
the body, but I could be wrong. You can have as many $
(document).ready(function(){});s as you want so I'd say your problem  must
have to do with having it inline. 

Joel. 



. 





[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Dan G. Switzer, II

Can jQuery be used inline?

It definitely can be. My guess is you're running into an error. Are you
using any JS debuggers to help you out. Firebug for Firefox is highly
recommended. MS also has a script debugger for IE--but it's not as intuitive
as Firebug.

-Dan



[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Joel Birch


On 16/04/2007, at 11:34 PM, Dan G. Switzer, II wrote:
PS - This really isn't addressed to Andy, just a general note.  
Sometimes we
developers get too stuck on following golden rules and we end up  
making
our code harder to work with. So if you find you have to go to long  
lengths
to code a corner case to a golden rule, just always think if the  
end pay off

is worth it. Ok, don't with my mini-rant. ;)


Yes there are always exceptions, which is I have been wracking my  
brain trying to think of the one ones that apply here, so thanks for  
your input Dan.


[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Andy Matthews

Sniff sniff...

I'll just go play on the Prototype mailing list now. 

-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Dan G. Switzer, II
Sent: Monday, April 16, 2007 8:34 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: New to jQuery and struggling


You should be able to use jQuery inline, but you might want to ask 
yourself WHY you want to use it inline. The power of jQuery is that it 
can affect EVERY part of the document from just one spot. I'd recommend 
rethinking your code so as to remove the need for inline JS.

While that is generally the best practice, there are exceptions for every
rule. The one place I do use inline JavaScript is when I'm leverage jQuery
for server-side component helpers (for example, Custom Tags in CF.) 

In this case, my jQuery code is generally outputted after the DOM element is
created. While not ideal, it makes it much easier to encapsulate all my code
into one helper function in my server-side code.

Having all your JS business logic in one place, definitely makes debugging
and modifying code easier, but there are times when inline code makes sense.

-Dan 

PS - This really isn't addressed to Andy, just a general note. Sometimes we
developers get too stuck on following golden rules and we end up making
our code harder to work with. So if you find you have to go to long lengths
to code a corner case to a golden rule, just always think if the end pay off
is worth it. Ok, don't with my mini-rant. ;)




[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread Dan G. Switzer, II

:)

I'm always amazed how much an emoticon can affect the meaning of a message.
I sent a sarcastic message to a friend once--which was the norm for us, but
left off the ;) emoticon. He got really upset with me (he was having a bad
day as it was.) The fact that I forgot the emoticon made him probably go
from laughing to be upset. 



[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread wls

 However, I am trying to add an additional $(document).ready(function()
 {}); in the middle of the document (i.e. inline) but it is not working
 and i don't know why.

I don't believe that you're going to find behavior chained.  Doing so
raises the interesting question of does your second function get
inserted before or after the existing chain, and if you are fairly
determined it should be one way, there's a dozen other people who can
reason why it should be the other.

The way I've been able to resolve this mentally is to consider that
each DOM's element handler has a single behavior associated with it.
When you invoke jQuery, you're patching that behavior handler.

Consider the case where you might have a button on the screen that
handles an onClick() event.  However, depending on some state, you
might want that button's behavior to change.  If you were simply
appending to handler chain, things could get really hairy.  Instead,
the solution is just to replace it.

Now, note, this is not a bad thing.  There is nothing at all that
prevents your .ready()'s anonymous function from walking through an
array of functions.  Effectively, doing a for-each like invocation on
everything.  That would allow you to register, in-line as you please,
additional functions, and at the end of it the ready() function would
do it's thing.

In short, make your function do the work, as you'll find the other
libraries do the same thing.  You can get the intended behavior, which
is to have one re-usable function who's job is to execute all the
things you ask it to.

-wls



[jQuery] Re: New to jQuery and struggling

2007-04-16 Thread skimber


On Apr 16, 2:36 pm, Joel Birch [EMAIL PROTECTED] wrote:
 Yes there are always exceptions, which is I have been wracking my  
 brain trying to think of the one ones that apply here, so thanks for  
 your input Dan.

I use JS/jQuery inline when I'm working on a dynamic PHP site with an
included header and footer for example.  I don't want to be including
the jquery library or code on every single page of a site - or adding
extra logic in my templates - when it's only needed for a few pages.