simple jquery problem - creating and calling functions

Joined
12 Feb 2006
Posts
17,651
Location
Surrey
this is seriously simple i know i just can't seem to do it, perhaps it's because it's late i don't know but i'm hoping when i get up someone can give me the nice and easy solution so i can get on with my work.

i want to create a function and then be able to call it from a timer.

i tried

PHP:
change1(function(){

// do cool jquery amazing stuff

})
didn't work :(

just in case it makes a difference what i'm trying to do is have 3 functions (change1,change2,change3) running one at a time. change1 checks if there is an element with id1, if yes do effect, wait a bit of time, then run change2, if id1 doesn't exist just do change2 straight away. change2 does same, checks, moves onto change3, which restarts again.
 
Isnt it;

PHP:
$(document).ready(function (change1) {

// do stuff here

});

OR

PHP:
function (change1) {

// do stuff here 

}
 
Code:
function change1(){

    // Cool jQuery stuff

}

and to set on timer...

Code:
$(document).ready(function(){

    setTimeout(change1(), 5000);

});
 
Something like the following to chain them. Prob an easier and neater way using jquery though.

Code:
$(document).ready( function()
{
    setTimeout(change1(), //timevalue in ms));
}

function change1()
{
    if (//id exists//)
    {
        setTimeout(change2(),//timeval in ms//)
    }
    else
    {
        change2()
    }
}

function change2()
{
    if (//id exists//)
    {
        setTimeout(change3(),//timeval in ms//)
    }
    else
    {
        change3()
    }
}

function change3()
{

}

edit- beaten :(
 
ah silly me that got it working, well almost.

the above is basically exaclty what i have just with the jquery stuff in it. the trouble is i get the following error: "missing ) after argument list" it says this for the line function change1() {

any clues why?
 
sorry, i missed the closing bracket round the $(document).ready( function()


should be

Code:
$(document).ready( 
    function()
    {
        setTimeout(change1(), //timevalue in ms));
    }
)
 
sorry, i missed the closing bracket round the $(document).ready( function()


should be

Code:
$(document).ready( 
    function()
    {
        setTimeout(change1(), //timevalue in ms));
    }
)


i tried this but now the fade effect doesn't work, only when in the document.ready(, however the script still does the result if that makes sense. e.g. i want to fade between text, rather then fading it just changes to text.
 
I put too many brackets in that - might be why. Do you know you can debug javascript in firefox in the error console. Would have picked that up straight away.

Code:
$(document).ready( 
    function()
    {
        setTimeout(change1(), //timevalue in ms);
    }
)
 
i tried this but now the fade effect doesn't work, only when in the document.ready(, however the script still does the result if that makes sense. e.g. i want to fade between text, rather then fading it just changes to text.

this is my problem ladforce, not the bracket problem you have said about.

i think i have realised the problem any way so thank you all for the help :)
 
Back
Top Bottom