SyntaxError: missing] after the list of elements [object Object]

I got this error in firebug:

     SyntaxError: missing ] after element list

    [object Object]

for the following javascript code snippet:

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 do not know how there may be absent there. By the way, in chrome I got this error:

Uncaught SyntaxError: Unexpected identifier
+2
source share
3 answers

setTimeoutexpects a function or line of code as the first parameter. You pass the result of evaluating this expression:

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

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

Do you want to:

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

, , setTimeouts . , , . , i , ...

+7

: -

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

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

as setTimeout .

+1

,

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

.

0

Source: https://habr.com/ru/post/1609910/


All Articles