Hello! I cant understand how to make a tweet button work correctly. I
ve installed it using the Tweet Developer Documentation. And Im trying to set a 'date-text' attribute by JQuery, but it doesn
t work. Would you please review my CodePen and help me to find out what am I doing wrong?
I’m not really sure how their widget works, but you can construct a URL to set your href to with the quote and author.
For example a tweet for hello world could be constructed with the URL below:
var url = https://twitter.com/intent/tweet?hashtags=hashtag&text=hello%20world
Note that spaces in the text should be replaced with %20 in urls
To set the href attribute, you can use $('.twitter-share-button').attr('href', url)
Thank you!
Ive seen solution like this, with the url. But if I can
t set the ‘text’ attribute, how can I change ‘href’ attribute?(( For some unknown reason I can`t control the ‘.twitter-share-button’ element by JQuery
I`ve decided to give up and make the button without the Tweet Button widget X))
The <a>
tag doesn’t have a text attribute, so that is why you are unable to control it using .attr(). For reference, the attributes for <a>
are listed here: https://www.w3schools.com/tags/tag_a.asp
If you define a tweet-url variable, a line like this should work to set the href attribute:
$('.twitter-share-button').attr('href', tweet-url)
I mean ‘data-text’ attribute, that supposed to be, and I could set it in html, but not by jquery. But I`ve deleted it anyway, so no matter)