change numbers into stars?
<p>I have this code witch works fine to change the number one into a star, but if I want several numbers like 1-5 to change into the same amount of stars(*) as the number is could I do this within the same loop or do I need to create 5 diferent loops, one for each number? </p>

<pre><code>function changeNumber()
{
    var elements= document.getElementsByClassName("grade");
    for (var i=0; i&lt;elements.length; i++) {
        var element = elements[i];
        var text = element.innerHTML; 
        var x = text.replace('1','*');
        element.innerHTML=x;
    }

}
</code></pre>

<p>this code gets the values the user typed in and places it in a array...</p>

<pre><code>var button = $('#add');
    button.click(function() 
    {
        //funktion för vad som ska hända när man klickar på knappen
        var filmnamn = $('#name');
        var filmnamnet = filmnamn.val();
        var betyg = $('#star');
        var betyget = betyg.val();
        betyget = Number(betyget);

        if(filmnamnet == 0)
        {
            $('#name').css('background-color', 'red');

        }
        if(betyget == 0)
        {
            $('#star').css('background-color', 'red');

        }
        if(betyget == 0 || filmnamnet == 0)
        {
            alert("Vänligen fyll i fälten korrekt");

        }
        else
        {
            var array = new Array();
            array.unshift(betyget);
            array.unshift(filmnamnet);
            film_array.unshift(array);
            betyg_array.unshift(array);
            updateFilmList();

        }

    });
</code></pre>

<p>Then the function updateFilmlist looks like this...</p>

<pre><code>    var film_list = $("#filmlista");
    var film_array = new Array();        

function updateFilmList()
    {
            document.getElementById("name").value = '';
            document.getElementById("star").value = 0;
            var filmen = film_array[0][0];
            var grade = film_array[0][1];
            var element = '&lt;li class="lista"&gt;' + filmen + '&lt;span class="betyg"&gt;'+ grade +'&lt;/span&gt;&lt;/li&gt;';
            film_list.append(element);
            changeNumber();

    }
</code></pre>

<p>And when I added the code you showed me in the changeNumber function the only number thats get changed into a star is the first list element in the dynamically created list... then the rest just shows up as numbers, why is that? btw you can ignore betyg_array since its for another function and has nothing to do with the problem...</p>
