Change all background color of <li> elements
7 answers
Typo Error:
Replace for (let i = 0; < x.length; i++;)withfor (let i = 0; i < x.length; i++)
Another typo:
; afteri++
Your JS is correct, it just has a typo.
var x = document.querySelectorAll("li");
for (let i = 0; i < x.length; i++) {
x[i].style.backgroundColor = "red";
}li {
color: white;
text-align: center;
border: 1px solid white;
font-weight: 900;
}<ul>
<li>YOUR</li>
<li>JAVASCRIPT</li>
<li>IS</li>
<li>WORKING</li>
</ul>+5
- css Javascript.
CSS
.red{
background-color:red
}
JQuery
$('li').addClass('red')
jquery red li. , . .
$('ol.selected li').addClass('red').red{
background-color:red
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ol>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ol>
<ol class='selected'>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ol>0