Search code examples
javascriptsyntax-errorproduction-environment

Another "Uncaught SyntaxError: Unexpected identifier"


Please, I'm having trouble with sntax and I don't know why. My script is

var popup = document.getElementById("mypopup");
var span = document.getElementsByClassName("close-btn")[0];
var sticker = document.getElementsByClassName("sticker")[0];

window.onload = function() {
  popup.style.display = "inline-block";
  sticker.style.display = "none";
}

span.onclick = function() {
  popup.style.display = "none";
  sticker.style.display = "inline-block";
}

window.onclick = function(event) {
  if (event.target == popup) {
    popup.style.display = "none";
    sticker.style.display = "block";
  }
}

and it seems the error is in the line

span.onclick = function() {

The console message is just "Uncaught SyntaxError: Unexpected identifier" and just appears on production environment.

Hope you can save me!


Solution

  • You need to use the addEventListener like so span.addEventListener("onclick", yourFunction) or it doesn't work