[jQuery] Re: Best event for changing the content of a div?

2008-11-05 Thread Chris

$(document).ready() is the soonest possible opportunity without using
inline script (and arguably sooner than an inline script).
You cannot use javascript to select your div until the DOM has been
loaded, and $(document).ready() fires as soon as the DOM has been
loaded. This happens before the page has loaded. The .load() function
is only fired after that element and all of its contents have
completely loaded. In the sequence of things, .load() happens after $
(document).ready() -- the DOM load -- and before onLoad -- the page
load.
More info:
http://www.learningjquery.com/2006/09/introducing-document-ready



On Nov 5, 3:30 pm, "Elwood Casey" <[EMAIL PROTECTED]> wrote:
> Correct: I'm not trying to change the content before the div loads.
> I'm trying to change it at the soonest possible opportunity, but without
> inline script!
> I'm hoping for an event that fires on a per element basis, when the element
> is ready - i.e $(element).ready().
>
> The only event that seems to match is load(), but I can't get this to
> fire...
>
> Looking at the docs, the load() event might be what I'm after
>
> On Wed, Nov 5, 2008 at 5:59 PM, Chris <[EMAIL PROTECTED]> wrote:
>
> > I could be mistaken here, but doesn't jQuery (or javascript for that
> > matter) need the DOM to be loaded before you can start selecting
> > things from it?
> > You could put the script elsewhere on the page, but you're still going
> > to have to wait for that div to load before you can change its
> > contents. If you to insert content before the page loads, you're going
> > to have to use some server-side programming, not javascript.
>
> > - Chris
>
> > On Nov 5, 11:12 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> > > If you don't want to put a script after the div it won't get any
> > > faster then DOM ready.
>
> > > You could although poll for that element. Say it had an id of
> > > 'asap' (untested):
>
> > > (function() {
> > >     var f = function() {
> > >         var div = document.getElementById('asap');
> > >         if (div) {
> > >             // alter content here...
> > >         } else {
> > >             setTimeout(f, 30);
> > >         }
> > >     };
> > >     f();
>
> > > })();
>
> > > --Klaus
>
> > > On 5 Nov., 16:30, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > I want to change the content of a div asap.
>
> > > > I know about document.ready, but if possible I'd rather do this
> > > > earlier. I'd also rather do it as an event instead of loading a script
> > > > file after the div appears in the page.
>
> > > > I tried the load() event, but this didn't seem to fire at all.
>
> > > > Anyone got any tips on this?
>
>


[jQuery] Re: Best event for changing the content of a div?

2008-11-05 Thread Elwood Casey
Correct: I'm not trying to change the content before the div loads.
I'm trying to change it at the soonest possible opportunity, but without
inline script!
I'm hoping for an event that fires on a per element basis, when the element
is ready - i.e $(element).ready().

The only event that seems to match is load(), but I can't get this to
fire...



Looking at the docs, the load() event might be what I'm after

On Wed, Nov 5, 2008 at 5:59 PM, Chris <[EMAIL PROTECTED]> wrote:

>
> I could be mistaken here, but doesn't jQuery (or javascript for that
> matter) need the DOM to be loaded before you can start selecting
> things from it?
> You could put the script elsewhere on the page, but you're still going
> to have to wait for that div to load before you can change its
> contents. If you to insert content before the page loads, you're going
> to have to use some server-side programming, not javascript.
>
> - Chris
>
>
> On Nov 5, 11:12 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> > If you don't want to put a script after the div it won't get any
> > faster then DOM ready.
> >
> > You could although poll for that element. Say it had an id of
> > 'asap' (untested):
> >
> > (function() {
> > var f = function() {
> > var div = document.getElementById('asap');
> > if (div) {
> > // alter content here...
> > } else {
> > setTimeout(f, 30);
> > }
> > };
> > f();
> >
> > })();
> >
> > --Klaus
> >
> > On 5 Nov., 16:30, the_woodsman <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > I want to change the content of a div asap.
> >
> > > I know about document.ready, but if possible I'd rather do this
> > > earlier. I'd also rather do it as an event instead of loading a script
> > > file after the div appears in the page.
> >
> > > I tried the load() event, but this didn't seem to fire at all.
> >
> > > Anyone got any tips on this?
> >
> >
>
> >
>


[jQuery] Re: Best event for changing the content of a div?

2008-11-05 Thread Chris

I could be mistaken here, but doesn't jQuery (or javascript for that
matter) need the DOM to be loaded before you can start selecting
things from it?
You could put the script elsewhere on the page, but you're still going
to have to wait for that div to load before you can change its
contents. If you to insert content before the page loads, you're going
to have to use some server-side programming, not javascript.

- Chris


On Nov 5, 11:12 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> If you don't want to put a script after the div it won't get any
> faster then DOM ready.
>
> You could although poll for that element. Say it had an id of
> 'asap' (untested):
>
> (function() {
>     var f = function() {
>         var div = document.getElementById('asap');
>         if (div) {
>             // alter content here...
>         } else {
>             setTimeout(f, 30);
>         }
>     };
>     f();
>
> })();
>
> --Klaus
>
> On 5 Nov., 16:30, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I want to change the content of a div asap.
>
> > I know about document.ready, but if possible I'd rather do this
> > earlier. I'd also rather do it as an event instead of loading a script
> > file after the div appears in the page.
>
> > I tried the load() event, but this didn't seem to fire at all.
>
> > Anyone got any tips on this?
>
>


[jQuery] Re: Best event for changing the content of a div?

2008-11-05 Thread Klaus Hartl

If you don't want to put a script after the div it won't get any
faster then DOM ready.

You could although poll for that element. Say it had an id of
'asap' (untested):

(function() {
var f = function() {
var div = document.getElementById('asap');
if (div) {
// alter content here...
} else {
setTimeout(f, 30);
}
};
f();
})();


--Klaus


On 5 Nov., 16:30, the_woodsman <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to change the content of a div asap.
>
> I know about document.ready, but if possible I'd rather do this
> earlier. I'd also rather do it as an event instead of loading a script
> file after the div appears in the page.
>
> I tried the load() event, but this didn't seem to fire at all.
>
> Anyone got any tips on this?