Skip to content
Advertisement

Uncaught ReferenceError: $ is not defined when is defined

Background I’m making 4 calendars:

  • The Current Calendar
  • Next Month’s Calendar
  • Last Month’s Calendar
  • 2 Month’s From now Calendar //$dateInt = date("U", strtotime("+2 months"));

I had the calendars building just fine, including the dynamic loading of values from my SQL Database Table (I’ll just call it DB henceforth) . I have been doing PHP off and on since the late 90s but for whatever reason, I’d forgot the concept of class, so I switched my “functions.php” page where the calendar loads and added the class and __constructor instead.

The calendars still build just fine, but the dynamic loading and adding of the values from DB has stopped and is now throwing the Uncaught ReferenceError: $ is not defined at calendar.php:466:29 error. I did not move the JQuery portion of the code at all (other than it’s inside a class now instead of a function

The Code

JavaScript

I’m sorry the for the length – I tried to take out everything I didn’t think was absolutely necessary. I can provide the full code if desired, just give me somewhere to send it to – it’s over 100 lines.

I did check the Dev Console and Sources sections in Chrome and did find that CentralCurrent11NonFlight does exist:

JavaScript

Originally I thought the problem was that the first $ was being echo’d as a variable, so I added the character to remove that: echo "<script>$('#$tdID').html('$display');</script>"; It didn’t fix the problem, but I’m going to leave it as it seems more… appropriate… within the echo.

Any thoughts would be helpful.

Thank you!

Advertisement

Answer

It was a DOM issue – on my calendar.php page at the very top, I had:

JavaScript

WAY before any of the DOM were created.

I moved it to the bottom of the page and it works just perfect.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement