Quote Generator: Trouble setting tweet text using attr()

I’m having trouble getting the current quote to appear in the tweet. The .attr() method works for retrieving the quote after $(document).ready, but for some reason it doesn’t seem to work within the .on() method. In other words, the default text in the tweet is always the quote that appears when the page loads, it doesn’t adjust to match the quote that appears after pressing the “new quote” button. I can’s see any reason why this would be. Is there something obvious I am missing? I’d appreciate any help or clarity anyone could give. Here is my code:

function selectQuote(){
return quoteArray[Math.floor(Math.random()*quoteArray.length)]
};

var newQuote = selectQuote();

(document).ready(function(){ (".quote p").text(newQuote);
$(".twitter-share-button").attr(“data-text”, newQuote);

(".new-quote").on ("click", function(){ newQuote = selectQuote(); (".quote p").text(newQuote);
$(".twitter-share-button").attr(“data-text”, newQuote);
});
});

Yes!

Thanks! That works and I at least think I understand why, it makes sense to generate a new tweet button each time.

The thing I still don’t understand is why my .attr() method worked when the page loaded but not after clicking the “new quote” button. Is it something I’m not understanding about the way the .attr() method and the .on() method work?