Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing ) after argument list

I am getting the syntax error:

SyntaxError: missing ) after argument list

From this jQuery code:

$('#contentData').append(
  "<div class='media'><div class='media-body'><h4 class='media-heading'>" + 
  v.Name + "</h4><p>" + v.Description + "</p><a class='btn' href='" + 
  type + "'  onclick="(canLaunch('" + v.LibraryItemId + " '))">
  View &raquo;
  </a></div></div>")

What kinds of mistakes produce this Javascript Syntax error?

like image 436
karthik Avatar asked Sep 21 '13 10:09

karthik


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.


2 Answers

You had a unescaped " in the onclick handler, escape it with \"

$('#contentData').append("<div class='media'><div class='media-body'><h4 class='media-heading'>" + v.Name + "</h4><p>" + v.Description + "</p><a class='btn' href='" + type + "'  onclick=\"(canLaunch('" + v.LibraryItemId + " '))\">View &raquo;</a></div></div>") 
like image 131
Arun P Johny Avatar answered Sep 22 '22 07:09

Arun P Johny


How to reproduce this error:

SyntaxError: missing ) after argument list

This code produces the error:

<html>
<body>
<script type="text/javascript" src="jquery-2.1.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){

  }
</script>
</body>
</html>

If you run this and look at the error output in firebug, you get this error. The empty function passed into 'ready' is not closed. Fix it like this:

<html>
<body>
<script type="text/javascript" src="jquery-2.1.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){

  });      //<-- notice the right parenthesis and semicolon
</script>
</body>
</html>

And then the Javascript is interpreted correctly.

like image 38
Eric Leschinski Avatar answered Sep 21 '22 07:09

Eric Leschinski