5

toggle.js

var $jq = jQuery.noConflict();
$jq(document).ready(function(){

    $jq('.isAdd').hide();

    $jq("#Add_category").change(function(){          
        var value = $jq("#Add_category option:checked").val();
        var theDiv = $jq(".isAdd");

        theDiv.slideToggle("slow");
    });
});​

In console I had:

Uncaught SyntaxError: Unexpected token ILLEGAL

For Firefox it's works fine, but not for Chrome and Chromium for Ubuntu.

TiSer
  • 775
  • 3
  • 11
  • 30

3 Answers3

14

There is an invisible character following the last }); of your last line. When I pasted it into my editor, it appeared as a ..

View your code in an editor capable of displaying non-printable characters with some kind of symbol, or view it in a hex editor.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Thanks, I copied and pasted so I'm assuming I copied an invisible character. After rewriting the code. It worked. – RedRory Jul 17 '12 at 15:42
  • 1
    You can also get this error when you paste in code with double quotes that are curly rather than straight. – awidgery Jun 22 '15 at 09:34
  • very useful tip! completely solve the problem on Chrome –  Apr 29 '16 at 02:26
0

To summarize the solution to problem with "Unexpected Token ILLEGAL":

ILLEGAL means strictly Syntax Error.

The Fix

Install HxD Editor (recommended) and open your file in it. You can detect where exactly the error is occuring by detecting unusual . (as it happened with me), with the code's HEX representation. Save and replace the file.

Syed Priom
  • 1,893
  • 1
  • 21
  • 22
-1

@TiSer: please check your code for invisible white space chars, on document ready handler is not the problem here, it was the illegal token direct after them – Irishka Oct 14 '11 at 13:57

yeap, it's right! Incredible - one small symbol and all JS code fell. :) – TiSer Oct 17 '11 at 8:50

$jq(document).ready(...); is causing this error Chrome

move your jQuery script to the bottom before < /body > tag

EDIT: check for white spaces

Community
  • 1
  • 1
Irishka
  • 1,136
  • 6
  • 12
  • i can give you some links to read: http://forum.jquery.com/topic/solved-problem-in-chrome-document-ready , http://stackoverflow.com/questions/5596904/jquery-document-ready-problem-with-iron-chrome – Irishka Oct 14 '11 at 11:38
  • `Unexpected token ILLEGAL` errors are caused by invalid syntax. The mere usage of a a ready handler cannot trigger such an error. – Šime Vidas Oct 14 '11 at 11:47
  • remove the ready event handler and error is gone, (replace change handler with delegate on the parent) – Irishka Oct 14 '11 at 11:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4264/discussion-between-irishka-and-sime-vidas) – Irishka Oct 14 '11 at 11:58
  • @TiSer: please check your code for invisible white space chars, on document ready handler is not the problem here, it was the illegal token direct after them – Irishka Oct 14 '11 at 13:57
  • yeap, it's right! Incredible - one small symbol and all JS code fell. :) – TiSer Oct 17 '11 at 08:50