Random Quote Twitter Button Problem

Hi Friends!

My twitter-share button is broken. Right now, I’m trying to create a new href attribute in the a tag for my twitter button as soon as the page loads by using .attr() in my .getJSON block. Here’s my full jQuery section:

$(document).ready(function() {
  let url = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
  
  $.getJSON(url, function(data) {
  $("#text").text(data.quoteText);
  $("#author").text(data.quoteAuthor)

//HELP HERE, PLEASE!
  $("#tweet-quote").attr("https://twitter.com/intent/tweet?text="+'"'+data.quoteText+'"'+"~"+data.quoteAuthor)
  });
  
  $(".btn").click(function() {
    $.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?", function(data) {
      $("#text").text(data.quoteText);
      $("#author").text(data.quoteAuthor);
    });
  });
});

and here is the html for my twitter a tag:

<a id="tweet-quote" target="blank" class="fa fa-twitter fa-2x"></a>

Any help is appreciated!

First thing I see is your jQuery attr call omits the actual attribute. Should be something like

$("#tweet-quote").attr("href", /* ... */)

It helps very much if you provide a Codepen or similar when you post an issue.