I'm making a list for the new football season where I want to plugin the results for each played round and display it in a list. I want to change the value of all "li" with less than 3 characters and instead display
I've tried coding a loop that looks through all elements with the tagName "li" and if the element has less than three characters, it replaces its innerHTML with "To be played".
<div>
<ul id="allResults">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
</div>
<script>
var parentGame = document.getElementById("allResults");
var listGames = parentGame.getElementsByTagName("li");
var listGamesLength = listGames.length;
for (var i = 0; i < listGamesLength; i++) {
if (listGamesLength[i] < 3) {
listGames[i].innerHTML = "To be played";
}
}
</script>
I'm quite sure that there is a lot of things wrong with my code, but I would like to know how to fix it - Or rewrite it in case it's completely wrong.
Thanks for the help! :)