Building a random quote generator

Building a random quote generator
0

#1

I am having trouble with the tweet button populating the quote correctly. I believe it is happening in this part of the code

$(’#tweet-btn’).click(function() {
window.open(‘https://twitter.com/intent/tweet?text=’ + $(’#quote’).text() + " " + $(’#author’).text());
});

When the code encounters a semi colon character within the quote it stops and doesn’t upload the rest of the quote, or the author. Anyone have any ideas on how to fix it? I provided a link below for the quote generator. Click through the generator until you find a quite with a semi colon and then click the tweet button and see what populates in the input field and you will see what the problem is. Thanks for the help.

https://codepen.io/Pew-pew-pew/pen/YYyGxP


#2

It looks like you can fix it by using the jQuery ‘replace’ function (assuming it’s only that character that’s causing issues). I think this works

  $('#tweet-quote').click(function() {
    window.open('https://twitter.com/intent/tweet?text=' + '\"'+ $("#quote").text().replace(/;/, '%3B') + '\"' + ' -'+$('#author').text());
    });

#3

You are awesome! That worked. I appreciate the help.


#4

window.open("https://twitter.com/intent/tweet?text=" + $("#quote").html());

the #quote was a p element. So i can easily get its text like this. You can also include your author in there too by adding +" "+ (if needed) then +author.


#5

This solution still causes the original problem. Once the quote gets to the semi colon it cuts off. The solution that r1chard5mith has recommended actually solved the issue. Thank you for responding to my request for help.