The solution is pretty simple.. Just use .each iteration and replace the string with desired URL
UPDATED ANSWER
Working Demo : http://jsfiddle.net/cmzqv/1/
Solution : Use Regexp
function(i,html) {
return html.replace(/(@\w+)/g, '<span class="twitterHandle">$&</span>');
});
Working DEMO : http://jsfiddle.net/cmzqv/
Code :
$(document).ready(function(){
$('.twitter').each(function() {
var handle = $(this).text().slice(1);
var handleUrl = "<span class='twitter'><a href='https://www.twitter.com/"+handle+"'>"+$(this).text()+"</a></span>";
$(this).replaceWith(handleUrl);
});
});