Reputation: 33
I'm working on a game in Jquery and would like to take the contents of a DIV (the score) and post it to Twitter:
<div id="score">
<p>You scored <span class="scoreToPost">800 points</span>!</p>
<p>Click <a href="">here</a> to post to Twitter</p>
</div><!--end score-->
And then after the user selects to post to Twitter, it would display in the Twitter pop-up box along the lines of something like:
@User: "I just scored 800 points in this cool game! #CoolGameTitle"
My problem is I can't figure out how to use the Twitter button API to grab the score within the span and pre-populate the Twitter field? Any ideas?
Thanks.
Upvotes: 0
Views: 353
Reputation: 64167
If you just need to parse the html to grab the score, you can use:
var html = $('.scoreToPost').html();
var matches = html.match(/^(\d+).*$/);
var score = matches[1];
alert(score);
Demo: http://jsfiddle.net/ZfsWr/
Upvotes: 1