> 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

Reply via email to