Issues with dynamically changing Twitter Button url

78 Views Asked by At

I built a very simple random quote generator. A bunch of quotes are stored in an array and one is displayed at any given time due based on a variable that holds the current quote. If a user clicks a button for a new quote, that variable changes and a new quote is displayed.

I'm trying to add a Twitter button to my page that will populate the tweet with the current quote. I used the Twitter for Websites Twitter Button instructions and went through the related material, but I still can't figure out what's going on. Currently, it works fine for the first quote but the quote doesn't change in the Twitter URL when you click "new quote."

The main logic is here:

function updateTwitterUrl () {
    var quote = encodeURIComponent(currentQuote);
    var url = "https://twitter.com/intent/tweet?text=" + quote;
    $(".twitter-share-button").attr("href", url);
}

And everything else is here: https://jsfiddle.net/37szaqpr/

0

There are 0 best solutions below