Twitter API Quote Generator Question


I’ve been struggling with this button for a while. Right now I have the button working, but not entirely correct. When the page first loads, the quote isn’t stored within the twitter button for its initial ‘data-text’ value. I’m not sure why because when the page loads it should’ve already ran my randQuote() function which would’ve set $(‘share’).html() to something other than just blank text (which right now seems to be happening). Afterwards, when the user clicks the button, then $(‘share’).html() grabs onto the quote before the change. Is there something I’m missing in the order of the functions? My codepen is here:

Any input would greatly be appreciated!



If I put a console.log in your setTweet function, I see that the “quote” isn’t set in the html yet, probably because of your fade in/out effects. What about removing the call to that function from lines 6 and 8 and put it on line 25? That way it will always get called immediately after the quote is set. And at that point, rather than make another call to the DOM, it might be faster to just pass the setTweet function the quote.


Amazing…I can’t believe i didn’t see that, thank you very much! It works! =D