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);
});
});