jQuery - button not responding to click?

Working on the quote generator, codepen here.

The button (“get-quote”) is not responding to a click. The console is logging the variable and “ready”, but nothing happens upon a click.

Relevant HTML:

   <div class="buttons">
      <a class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
        Tweet Wisdom
      </a>
      <button class="button" id="new-quote">More Wisdom</button>
    </div>

Relevant JS:

var changedtext = "TEXTCHANGED";
var changedauthor ="AUTHORCHANGED";

console.log(changedtext);

$(document).ready(function(){
  $(id="new-quote").click(function (){
                          $(id="quote-text").text("CHANGEDTEXT");
                          $(id="quote-author").text(changedauthor);
                         console.log("clicked") });
console.log("ready")})

Thanks!

Because of the way you are selecting elements by id.
Change $(id="new-quote") to $("#new-quote"). Do the same for all the id selectors.

1 Like

Hello there.

I think you are wanting:

$("#new-quote")

Read more about jQuery Selectors here: https://www.w3schools.com/jquery/jquery_selectors.asp

Hope this helps

1 Like