I am working on little project to learn jQuery, and I have a twitter plugin which you enter a username to see the tweets of that user. Elsewhere on the site I have a simple text input field which I’m hoping can take an entry and append it to where the username is in the existing code… Is this possible? Maybe using the append string, or .text?
Where you can see rjames83, that’s what I’d like to replace with the contents of a text field.
$(document).ready(function(){
// Get latest 6 tweets by jQueryHowto
$.jTwitter('rjames83', 6, function(data){
$('#posts').empty();
$.each(data, function(i, post){
$('#posts').append(
'<div class="post">'
+' <div class="txt">'
// See output-demo.js file for details
+ post.text
+' </div>'
+'</div>'
);
});
});
});
All you do is wrap the $jTwitter block in a function and pass it a parameter.
Wherever you are typing in the new user to grab tweets for, simply add this to the onclick of the button to make it fire: