Posting Randomly generated quotes from codepen to twitter

The following code send the link of my codepen to twitter but I wan to send just the quote text from the codepen.
HTML and JQuery part is as following:-1:

<div id="tweet" class="text-center">         
  <a href="http://twitter.com/share" class="twitter-share-button"
   data-text="This is what we want to change dynamically"    
    data-count="none" data-via="bindu_verma">Tweet</a>        
      </div>  

$('a[data-text]').each(function(){
      $(this).attr('data-text', "This works!");
   
    });
    $.getScript('https://platform.twitter.com/widgets.js');

I’ve spent a long time trying to adapt the Twitter Share button. The problems I encountered were:

  • widget.js replaces the <a> element with an <iframe>. It has a corresponding <a> deep inside its bowels but with a hard coded query in the href. There are no data-* properties anywhere to fiddle with.

  • So I replaced the button every time the quote was updated, using the factory function createShareButton offered by widget.js to create the button. It worked but it was slow and you could see the button disappear and reappear.

  • I tried using a documentFragment to do the DOM manipulations without refreshing the screen but I couldn’t make it work with createShareButton.

In the end, I gave up on the Twitter Share button and implemented it with a Web Intent URL. A lot easier to implement and it works well.

Can you show your example to see how it works?