Obromios Obromios - 2 years ago 115
Javascript Question

jQuery DOM event listener failed with "$ is not defined"

Following the advice here, I have the following inline code in a Ruby on Rails app:

document.addEventListener("DOMContentLoaded", function(event) {

I am getting an error
$ is not defined
. However, if I click on a link to go to the page, then the code works fine, so my
assets are loading, given sufficient time.

Answer Source

try this:

document.addEventListener("load", function(event) {


The DOMContentLoaded event is fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading (the load event can be used to detect a fully-loaded page).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download