BrianJ
BrianJ

Reputation: 39

Display a link to the status of my latest tweet using jQuery & how to execute it?

So I have jQuery in the <head> of my page as this:

<script language="javascript" type="text/javascript" src="./javascript/jquery-1.2.6.js"></script>

and already I was gratefully given this code that will display a linked text that reads 'Read' and the link will be to my latest tweet's status and it looks like this:

jQuery.getJSON('http://twitter.com/status/user_timeline/brianj_smith.json?count=1&callback=?', function(data){
if (data.length > 0) {
    var link = jQuery('<a>').attr('http://twitter.com/brianj_smith/status/' + data[0].id)
                            .text('Read');
});

Now I am not an expert at jQuery, so I don't exactly know how to make the above jQuery coding work and for the text "Read" to be displayed on my website, while at the same time it being linked to the status of my latest tweet.

I think that makes sense for the most part. If anyone could help me out that would be great. I know I made a post earlier, but I didn't understand much of what was being said :S

Upvotes: 1

Views: 285

Answers (2)

penguinrob
penguinrob

Reputation: 1459

You would just add @Ben's code in your existing:

jQuery.getJSON('http://twitter.com/status/user_timeline/brianj_smith.json?count=1&callback=?', function(data){
$('#tweetlink').append('<a href="http://twitter.com/brianj_smith/status/' + data[0].id_str + '">Read Tweet</a>');
});

Upvotes: 1

Ben Collins
Ben Collins

Reputation: 20686

You would use jQuery to get a reference to the element that should contain your link and append the newly created link:

$('div-to-contain-the-link').append(link);

Upvotes: 2

Related Questions