So I am attempting to do the part about tweeting out the quote that is generated. I have the twitter button present and to start with it has a default href of: href=“https://twitter.com/intent/tweet?text=Hello%20world” just for testing.
When clicking the tweet button it opens another window with a tweet that has exactly what you would expect.
What I have done is created a jquery to hopefully update that href to instead of saying “hello world” in the tweet, to have the quote string.
The problem is that it is not updating.
Here is my jquery line:
$(".twitter-share-button").prop(“href”, newlink);
I have also tried:
$(".twitter-share-button").attr(“href”, newlink);
$("#twittershare").attr(“href”, newlink); (using the anchor link’s id attribute instead of the class)
I also tried to use replaceWith and I couldn’t figure that out either.
Still not having any luck… I click it after updating the quote and it still has the “hello world” in the pre-made tweet.
and yes I have a window alert. That was just to make sure that I have the correct link in the javascript variable which it seems that I do.
I assume its either something with the twitter button I am using or maybe you cant update href attr after the page is loaded or something weird like that… any ideas?
@Lawyerscode I think I read somewhere on the twitter pages that it needed to be formatted like that. I took the link that pops up after you hit new quote and put it into browser and it gives the right link with the right pre-filled text. And I think even if that was the case, it would still get rid of the hello world text, no?
another solution a friend suggested me was to use an onclick for the link and to call a function to build the link that I need except the only issue with that is the value I need for the link uses a random number generated in the already existing function so I don’t see a way to get that same random value out of that function to use in a new different onclick function.
Yeah I commented that out and that did fix it. Weird. That was what the twitter page told me to use to bring in the function that creates the little blue “tweet” button. Its supposed to detect the class=“twitter-share-button” and make the link into a button. Because now the link isn’t a button its just a link. That’s odd.