tags:

views:

70

answers:

2

I have some HTML:

<div id="tagCloud">
<a class="5" title="1 records" href="tags=Battleship">Battleship</a>
<a class="4" title="1 records" href="tags=Cabbage">Cabbage</a>
etc...

I want to take the class value, and convert it to a word.

So if class = 5 append class five?

A: 

This will replace all classes called 5:

$(".5").removeClass("5").addClass("five");

If you want to automate it for any class with a digit name, then it is going to be more difficult. I would make a custom selector that could pick out classes with only numbers (based on regex), then use each to loop through and find out what that number was, for each element, and then create a function for translating a number into english, and then add that class. Note that this wouldn't be terribly fast though.

Marius
This is the literal way to handle the case for 5 / five, but doesn't generalize, which is what I think @danit is asking.
Tony Miller
A: 

If you know the maximum class number, you can do this (with max being 10):

var nums = new Array("zero","one","two","three","four","five","six",
                     "seven","eight","nine","ten");
for (var i = 0; i < nums.length; i++)
{
    $("." + i).addClass(nums[i]);
}

I don't know of any way to more dynamically get the text of a number, but something may exist.

rosscj2533