Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing ] after element list [object Object]

Tags:

javascript

I got this error in firebug :

     SyntaxError: missing ] after element list

    [object Object]

for the following javascript piece of code :

for ( var i = 0; i < 4; i++ ) {
    setTimeout( function(){
        closeBtn( i,'.lt400' );
        // the error exactly happened in next line:
        setTimeout($('#uploaded-holder').hide(), i * 300 );
    }, i * 300 ); 
}

I don't know how a ] can be missing there.. by the way, in chrome i got this error :

Uncaught SyntaxError: Unexpected identifier
like image 383
Bardelman Avatar asked Feb 07 '26 21:02

Bardelman


2 Answers

setTimeout expects a function or a string of code as the first parameter. You are passing the result of the evaluation of this expression:

$('#uploaded-holder').hide()

This expression returns neither a string, nor a function. It returns a jQuery collection.

You want:

setTimeout(function () {
    $('#uploaded-holder').hide();
}, i * 300 );

You have an odd set of code there, though, given the combination of setTimeouts and the loop. I would expect some wild oddities to come from it once this error is resolved. For example, i is not going to be what you expect in the execution of many of those internal functions...

like image 82
JAAulde Avatar answered Feb 09 '26 11:02

JAAulde


You may try to use this:-

setTimeout( function () 
{ $('#uploaded-holder').hide() }, i * 300 );

instead of

setTimeout($('#uploaded-holder').hide(), i * 300 );

as setTimeout expects a string or a function as first parameter.

like image 45
Rahul Tripathi Avatar answered Feb 09 '26 10:02

Rahul Tripathi