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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With