Reputation: 303
My JSON works fine. I'm able to modify the quote-text and the quote-author every time I click my "Gimme A' Quote" button. However, I'm experiencing problems each time I try to post a tweet using the quote's text and author. Whenever I click on the twitter symbol, the page just refreshes.
I've been trying to add the quote content and author into the Tweet by doing this:
var twitterIntent = 'https://twitter.com/intent/tweet?text=' + quoteText + 'Author' + quoteAuthor + ' @myleschuahiock';
And subsequently telling JQuery to do this whenever I click on the "Gimme A' Quote" button:
$('.quote-button').click(function(){
getQuote();
colorRandomizer();
$('.twitter-share').attr("href", twitterIntent);
});
My code is located here: http://codepen.io/myleschuahiock/pen/WrVgzB Please take a look!
Can someone tell me what I'm doing wrong? Thanks and much appreciated!
This project is my submission for Free Code Camp.
Upvotes: 4
Views: 840
Reputation: 2032
You are defining twitterIntent
inside of the getQuote()
function, but then trying to use it outside of that function. If you check the console for errors it shows that twitterIntent
is uindefined after you click the button. Instead, you can just change the href
attribute of the .twitter-share
link inside of the getQuote()
function.
Just add the line $('.twitter-share').attr('href','https://twitter.com/intent/tweet?text='+quoteText+' Author: '+quoteAuthor+' @myleschuahiock');
where you are changing the contents of the .quote-content
and .quote-author
areas like the example below.
json.forEach(function(val) {
quoteText = val.quote;
quoteAuthor = val.author;
$('.quote-content').html(quoteText);
$('.quote-author').html(quoteAuthor);
$('.twitter-share').attr('href','https://twitter.com/intent/tweet?text='+quoteText+' Author: '+quoteAuthor+' @myleschuahiock');
});
Then all you have to do is remove $('.twitter-share').attr("href", twitterIntent);
from $('.quote-button').click()
, and you're all set.
Upvotes: 2