1

Whenever I pass .on() functions as parameters it doesn't work, but if I define the function itself inside of the parameters, despite having the exact same code, it then works

For example, this does not work:

  function foo(){
    alert("Yo")
  }

  $(window).on("click", foo())

While this does:

  $(window).on("click", function(){
    alert("Yo")
  })

1 Answers1

0

You're calling the function there.

You should pass its reference like this

 $(window).on("click", foo)
Terminat
  • 1,199
  • 5
  • 21