Mathias,

>Don't register your ready functions like this:
>
>$(document).ready(...);
>
>Register it like this:
>
>$(document).bind("ready",...);
>
>Now, trigger the ready event:
>
>$(document).trigger("ready");
>
>This works. I think, it's a bit confusing, because $(document).ready
>is an event (at least in the api). So, I expect, that it can be called
>like an event.

As already suggested, I think the *best* method is:

function initPage(){
        // do stuff
}

// call the initPage when the DOM is ready
$(document).ready(initPage);

Now all you need to do is re-run the initPage() whenever you want to re-run
that code.

Plus you stated you need to "which needs to refresh *nearly* the complete
page." This even more feels like you're best to break off the code that does
need to be refreshed from that code that does not need to be refreshed. This
means this method would even be better:

// init new DOM elements
function initDomFrag(){
        // do stuff here
}

$(document).ready( function (){
        // stuff only needed to be run on initial page load
        $("#hide").hide();

        // reinit DOM fragment
        initDomFrag();
});

I'd just isolate the exact code that needs to be re-used into it's own
function. That seems like the purest solution to me. Re-running the
$(document).ready seems hackish to me.

-Dan

Reply via email to