0

I have following simple code (from here) and Firefox 49.0.1 says it has a Syntax Error in the last javascript line:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<script>
    function doit(e) {
        var eventType = e.type;
        console.log("hello");
      var files = e.target.files;
      var reader = new FileReader();
      reader.onload = function() {
        var parsed = new DOMParser().parseFromString(this.result, "text/xml");
        console.log(parsed);
      };
      reader.readAsText(files[0]);
    }

    document.getElementById("selectfile").addEventListener("change", doit, false);​ // Syntax Error here.
</script>

<input type="file" id="selectfile" />
</body>
</html>

Picture: enter image description here

I really don´t have a clue whats wrong. I appreciate your help.

5
  • check that that's not some invisible/unprintable char on that line, or the lines before. Commented Sep 27, 2016 at 16:00
  • After the ; on that line, there's a U+200B character you can't see. Put your cursor on that ;, delete it and the spaces and // after it, then type them back in. (I used to see this a lot on JSBin, perhaps you were using JSBin?) Commented Sep 27, 2016 at 16:01
  • You can just delete the question, it's not going to be useful to others in the future. (Well, you can't directly anymore, someone answered and it got upvoted. But you can flag and ask a moderator to.) Commented Sep 27, 2016 at 16:02
  • @T.J.Crowder You get a penalty if you delete a question within 30 days. Commented Sep 27, 2016 at 16:05
  • @Bálint: Isolated examples are fine. It's repeated ask-and-delete that's an issue. Commented Sep 27, 2016 at 16:06

1 Answer 1

3

You have the illegal character U+200B after the semicolon on that line. It's a whitespace character, so you can't see it. Just backspace/delete it, and then type a normal space.


See: this JSFiddle highlights the bad character.

Sign up to request clarification or add additional context in comments.

5 Comments

This is basically a "typo" question. They get commented and deleted rather than answered.
@T.J.Crowder oh ok. Is there precedent for that? Like, a meta post or something for how to approach it in the future/now?
Somewhere on meta, yeah, this was established years back. :-)
Not a "bad," just something you didn't know. :-)
For sure. Well, I'll keep that in mind for the next question like this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.