goulashsoup goulashsoup - 2 months ago 21
Javascript Question

Javascript SyntaxError: illegal character in addEventListener line

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.

Answer

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.