SCRIPT1002: Syntax Error, Line 1 Character 6

51,036

"WAIT... does IE9 not like <a href="javascript:void();" id="donateButton"> ?? It seems thats the problem..?"
Comment by Chud37

Yes, that is the problem. void is an operator, not a function. Use javascript:void 0 , javascript:void(0) or #. Even better, add event.preventDefault() to your function:

$('#donateButton').click(function(ev) {
    ev.preventDefault();
    alert('hello');
});
Share:
51,036
Chud37
Author by

Chud37

I am a 30 year old programmer living and working in the UK. I use PHP, jQuery and SQL. I build and maintain several websites for my job.

Updated on July 09, 2022

Comments

  • Chud37
    Chud37 almost 2 years

    In the IE developer (F12) console, I've managed to get my pages to run without errors; all but one!

    SCRIPT1002: Syntax error
    mypage.php, line 1 character 6

    I am using IE9. Whats it's problem?

    This is my code:

    <!DOCTYPE html>
    <head>
      <script type='text/javascript' src='/files/jquery-1.7.2.min.js'></script>
      <script type="text/javascript">
        $(document).ready(function() {
          $("#donateButton").click(function() {
            alert('hey');
          });
        });
      </script>
    </head>
    <body>
      <a href="javascript:void();" id="donateButton">asdsadasd</a>
    </body>
    

    When I click on #donateButton an error is produced. However, when I change javascript:void() to # then no error occurs any more. Why?