0

I have written some JavaScript code which, when run, produces the following error:

"error"
"SyntaxError: Unexpected token ILLEGAL

I don't know what does this error mean. I tried googling it but couldn't find anything useful.

Here's my code:


HTML:

$(document).ready(function(){
   $('#fostering').on('click', function(){
       $(this).animate({
           width : 50px;
       });
   });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
        <meta charset="utf-8">
        <title> Something </title>
    </head>
    <body>
        <div id="fostering"></div>
    </body>
</html>

So,

  • What's causing this error?
  • How do I resolve it?
Arjun
  • 1,261
  • 1
  • 11
  • 26
  • width : 50px; remove the semicolon – EugenSunic Sep 05 '15 at 23:24
  • The error is thrown because you don't put `50px` inside quotes. Also there shouldn't be a semicolon after `width: "50px"` –  Sep 05 '15 at 23:39
  • 1
    It's ok, well it arises when you have a character at a place where it shouldn't be. Basicaly if you want to read more on how JS parses the given code then here is a good article about it: http://stackoverflow.com/questions/12719859/no-visible-cause-for-unexpected-token-illegal – EugenSunic Sep 05 '15 at 23:40

1 Answers1

2

Remove the semicolon and put it in a quotation (width attribute value):

  $('#fostering').on('click', function(){
     $(this).animate({
      width : "50px"
     });
    });

This error arises when you have a character at a place where it shouldn't be. Basically, if you want to read more on how JS parses the given code then here is a good article about it,

URL: No visible cause for "Unexpected token ILLEGAL"

Community
  • 1
  • 1
EugenSunic
  • 13,162
  • 13
  • 64
  • 86