I am looping out my posts from the database and i am trying to change color of the votes depending on value. If 0 = Black, < 0 = Red, > 0 = Green. My first attemp was to set an id on the h1 tag for the vote value and modify the color from that way. It worked for the first post but all other posts are not affected. Does anyone have any other idea of how i could do this?
PHP & HTML:
while ($row = $stmt->fetch()) {
echo '<h1 id="scoreCounter">'.$row['votes'].'</h1>';
}
Javascript:
var score = document.getElementByid("scoreCounter");
var scoreValue = 10;
checkScore();
function checkScore() {
if (scoreValue < 0) {
score.style.color = "#FF586C";
} else if (scoreValue > 0) {
score.style.color = "#6CC576";
} else {
score.style.color = "#666666";
}
}