javascriptjqueryjsfiddlejsbin

How to resolve JavaScript 'Unxpected Token Error'?


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,


Solution

  • 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"