Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: SyntaxError: missing ) after argument list

I am getting the error:

SyntaxError: missing ) after argument list

With this javascript:

var nav = document.getElementsByClassName('nav-coll'); for (var i = 0; i < button.length; i++) {     nav[i].addEventListener('click',function(){             console.log('haha');         }     }, false); }; 

What does this error mean?

like image 868
Ismaël tifous Avatar asked Mar 21 '13 21:03

Ismaël tifous


People also ask

How do you fix a missing after the argument list?

The "SyntaxError: missing ) after argument list" occurs when we make a syntax error when calling a function, e.g. forget to separate its arguments with a comma. To solve the error make sure to correct any syntax errors in the arguments list of the function invocation.

How do you find the uncaught SyntaxError missing after the argument list?

The “SyntaxError: missing ) after argument list” error is raised if a function call cannot be evaluated correctly. To fix this error, make sure your arguments are formatted correctly. Double-check that all of the arguments in the function call are separated by commas.

What does missing after argument list mean?

The JavaScript exception "missing ) after argument list" occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.


1 Answers

You have an extra closing } in your function.

var nav = document.getElementsByClassName('nav-coll'); for (var i = 0; i < button.length; i++) {     nav[i].addEventListener('click',function(){             console.log('haha');         }        // <== remove this brace     }, false); }; 

You really should be using something like JSHint or JSLint to help find these things. These tools integrate with many editors and IDEs, or you can just paste a code fragment into the above web sites and ask for an analysis.

like image 148
Ted Hopp Avatar answered Sep 18 '22 10:09

Ted Hopp