Add text to twitter share API via jquery/javascript

283
August 07, 2017, at 2:42 PM

I can't manage to make jQuery add the content of #quote (which is a paragraph with a string generated via foresmatic API).The full code is here: https://codepen.io/raffaele2692/pen/GvrvxM .... Can you help me? :)

<a type="button" class="twitter-share-button"
href="https://twitter.com/intent/tweet"
data-size="small"
data-text="">
Tweet</a>

<script>
var textQuote = document.getElementByID("#quote");
$("a").attr("data-text", textQuote);
</script>
Answer 1

You have some issues in the js code. You do not need to add "#" to the id for getElementByID call , also to get the text of a HTML element you can use text method.

<script>
var textQuote = $("#quote").text();
$("a").attr("data-text", textQuote);
</script>
Answer 2

I think textQuote is a HtmlElement object, not the value you want to assign. you should get the value in quote first. btw, jquery has a method called data to assign value to data attributes.

Rent Charter Buses Company
READ ALSO
How to get html script src value from js file?

How to get html script src value from js file?

My question is about making src in html script tag dynamicNow, I have something like this at the bottom of the html :

466
Can I send data from Ionic JS Popup?

Can I send data from Ionic JS Popup?

I try build android and in some page I'll make edit from popupExample if i click input it will show popup and on popup be found input text

345
How to execute a set of JavaScript code only if HTML form validation is succesfull

How to execute a set of JavaScript code only if HTML form validation is succesfull

I have a HTML form with some fields and a submit buttoncouple of fields are mandatory

274
Show specific index input and hide others

Show specific index input and hide others

I am stuck in a problemi have added a label and input in ng-repeat

303