I think it depends on what you are doing in those click functions. If
they inherently call timeout/interval code, then they are non-blocking
by nature and you will need to edit them in able to be able to pass in
a callback of some sort. If the click handlers are already blocking,
though, then you can just call them as you have above. This code
illustrates that: it adds a 1/2 second script to every paragraph in
the page, then executes them.
$("p").click(function() {
var timeout = new Date().valueOf() + 500;
console.log("click started at " + timeout);
while (timeout > new Date().valueOf()) {
// wait
}
console.log("click done at " + new Date().valueOf());
}).click();
If you run it, you will notice two things: 1) the scripts execute
sequentially (and could have been put on separate lines as in your
example), and 2) it is a blocking script, so you must wait until all
are done before you see any output. If you have a lot of paragraphs
on you page, you will probably get an 'unresponsive script' error.
This could be mitigated without sacrificing your original intent by
triggering each click on a short timeout, but it gets complicated with
many and/or variable items.
$("p:eq(0)").click();
window.setTimeout(function() {
$("p:eq(1)").click();
window.setTimeout(function() {
$("p:eq(2)").click();
}, 5);
}, 5);
// etc...
o
On Jul 24, 5:37 pm, tuliopaiva <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I have 3 buttons (id's "bt1", "bt2" and "bt3"), and each one has a
> onclick funcion that is a ajax function. I want to execute this code:
>
> 1 $("#bt1").click()
> 2 $("#bt2").click()
> 3 $("#bt3").click()
>
> but to execute the line 2, the line 1 must have finished the
> execution, and the line 3 shoud be executed when the line 2 finished
> (all funcions are ajax functions).
>
> How can I do this???
>
> Thanks.
>
> []'s