0

I have to do some homework with JavaScript. The Exercise is: We programmed a Game called ColorClicker. Very simple. When you win this game, I want to show the 10 best Scores in a list. Now I want to connect this list with my CSS, so I can make it look cooler etc.

My Code in JS:

function showHighscoreList(topTen) {
    var rank = 1
    topTen.forEach( function(entry) {
        var list = document.getElementById("highscoreList"),
            listElement = document.createElement("li"),
            entryElement = document.createElement("i");
        entryElement.innerHTML = "Platz "+rank+" - Username: " + entry.user + " | Score: " + entry.score;
        rank++;
        list.style.backgroundColor="orange";
        listElement.style.fontSize = "larger";
        listElement.addEventListener("click", onHighscoreListClicked);
        listElement.appendChild(entryElement);
        list.appendChild(listElement);
    });
}

And that's my code in HTML:

<div id="highscore">
        <ul id="highscoreList">
        </ul>
</div>

So, now I want to manipulate the HTML elements with CSS. How can I do that in detail?

2 Answers 2

3

Stylesheet are linked to HTML document using link tag,

<link rel="stylesheet" href="path-to-your-file/style.css">
Sign up to request clarification or add additional context in comments.

Comments

0

This two lines are already css manipulation:

list.style.backgroundColor="orange";
listElement.style.fontSize = "larger";

Maybe you can add a class attribute and then apply some css to them:

list.class="list-element list"+rank;

And in css:

.list-element {
    font-size: 12pt;
    /* Other common styles */
}
.list1 {
    color: red;
}
.list2 {
    color: blue;
}

/* And so on...*/

I hope it helps.

1 Comment

Small tweak: class is not a valid keyword in JavaScript, so the element class attribute is renamed to className (and has expected effects)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.