jQuery issues with attaching event listener using .on() [solved]

I’m working on the random quote generator project. I was having some issues fetching data and boiled it down to an issue with attaching an event listener. With this code:

<button id="new_quote" class="button">NEW QUOTE</button>

console.log("Logging");

$(document).ready(function() {
  $("#new_quote").on("click", function() {
     console.log("button clicked");
 });
});

“Logging” is logged, but clicking the button does not cause “button clicked” to be logged. What might I be missing here?

The code should work. Do you get any errors in the console? Did you maybe forget to include jQuery?

can you add a console.log inside your
$(document).ready(function(){console.log("inside ready function"); ...})
if it’s not logged, that means that jquery is probably not loaded in your pen.

Both correct. I did not have jQuery loaded. Thanks for helping me find my omission!

1 Like