Issue trying to dynamically change Tweet Button URL

tweetbutton

#1

I’ve built a simple Random Quote generator and I want to tweet the current quote which is stored in a global variable. On the page there’s a button that a user can click to generate a random quote, which changes the value of the currentQuote variable. I’ve followed the Tweet button instructions, however once a user clicks the button to generate a new quote, the tweet URL does not change. This is the current state of the update function, although I’ve tried a number of things out at this point:

function updateTwitterUrl () {
	var quote = encodeURIComponent(currentQuote);
	var url = "https://twitter.com/intent/tweet?text=" + quote;
	$("#twitter-section").empty().append( '<a class="twitter-share-button" href="' + url + '"> Tweet</a>' );
}

This gets me close to what I want, however it removes the Twitter widgets functionality - the button and count no longer appear. The link text, however, remains and is correct.


#2