views:

42

answers:

1

I have a desktop gadget that pulls RSS Feeds from a website. The Feed contains information about issues - ie. Priority, Time, Description.

The Feed items are displayed on the desktop - however I need to colour code them according to their priority ie 1 = red etc. using the substr function - is there a better way to do this using JavaScript / HTML?

At the moment I've hacked together this - but is there a more elegant solution?

if (feed.item.description.substr(10,1) == "1")
{
document.write "<a href colour="red"" + item + ">";
else if (feed.item.description.substr(10,1) == "2")
{
document.write "<a href colour="yellow"" + item + ">";
else
{
document.write "<a href colour="green"" + item + ">";
A: 

Why not do it with CSS? Give the anchor tags a class (or more than one class) based on the priority or whatever, and then use a CSS file to drive the style.

document.write("<a href='(whatever)' class="description_" + feed.item.description.substr(10, 1));

or something like that. Then your CSS file would say

a.description_1 { color: red; }
a.description_2 { color: yellow; }

etc

Pointy