Random Quote Generator : How to add current quote to the twitter link?

Random Quote Generator : How to add current quote to the twitter link?
0.0 0

#1

Hi, I am working on my random quote generator but I cannot get the quote to be displayed on the twitter link. I tried several solutions but could not fix the problem. Here is my pen

https://codepen.io/Aisha1/pen/KZvGJE


#2

First of all, you need to add JQuery to the Codepen settings under JS --> Add External Scripts/Pens.

Second, the following code has a problem.

  <div class = "tweet">
  <a id = "tweet1"  href = "https://twitter.com/intent/tweet?" target = "_blank"><button id = "tweetbutton1" >Tweet</a></div>

You attempted to put button inside the anchor tag and you have a malformed button (missing closing button tag). The correct button syntax would be:

<button id="tweetbutton1">Tweet</button>

Honestly, you do not even need the anchor tag, because your tweet button event handler takes care of opening a new window. You could simply put the following:

  <div class="tweet">
     <button id = "tweetbutton1" >Tweet</button>
  </div>

The last problem is you should move the following code to be outside of the genQuote function, because if not, you are adding extra click events each time the New Quote button is clicked.

$("#tweetbutton1").click(function() {
   window.open("https://twitter.com/intent/tweet?&text=" + quote);
});

#3

Got it, thank you for the help!