More questions on parsing Twitter Feeds


I found these really neat functions for parsing links, hashtags and unsernames in twitter feeds (i.e., convert them to links… why on earth don’t they come in as links already???.. ;-o)

but now I’m trying to “get cute” and give the different links (regular links, usernames, hastags) different font colors (would love to find a way to add an “addClass” functionality to those parsing functions…:wink: so came up with my own funky code, and needless to say, am running into problems… either it works and only one record prints, or I move this block of code somewhere else, and then all records print again, but font color doesn’t change…

my entire code, with comments explaining problems (which are numerous):

//	********** set font color for the links -- PROBLEMS ARE HERE.........
	$('#results a').each(function(i) {
	//	$(this).css('color','green'); // this test line sets font color for all links except tweet url (??)
		var hrefAttr = $(this).attr('href');
		console.log('hrefAttr -- ' + hrefAttr);	//	prints fine, but on below line get 'undefined' (???)
	//	if link is hashtag link	
	//	********* GET ERROR 'undefined' ON BOTH THESE TWO LINES (???) ********
		if ( $(this).attr('href').indexOf('/search?q=') != -1) {
	//	if ( hrefAttr.indexOf('/search?q=') != -1) {
			$(this).addClass('linkHTag'); // works, but only one record prints..  if I comment out 
										// this entire font-color block then all records print...(????)
										// tried putting this block outside $.each method, then  
										//	it prints all records, but the font colors don't change...
		//	if link is user link
		/*	if (hrefAttr.indexOf('/search?q=') == -1 && hrefAttr.indexOf('/') == -1 && hrefAttr.indexOf('/status/') == -1) {
				$(this).addClass('linkUser');	//	doesn't work at all....

I hope this is enough to glean problem… (this code is inside $.each fn where I parse the data (right after I print the content with .html() method…) just in case, entire .js is here…)

thank you…


As a side note, libraries for accessing Twitter data already exist. Have you had a look at those?

Parsing HTML output can be tricky as it can change without warning.