Bonjour,
je ne comprend pas pourquoi getElementsByClassName ne récupère pas toute les class et fait les modification voulu en fonction du click
Le html :
Le css :
Le JavaScript :
cordialement
je ne comprend pas pourquoi getElementsByClassName ne récupère pas toute les class et fait les modification voulu en fonction du click
Le html :
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Type New Todo</p>
</div>
<div class="Content">
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Complete online JavaScrip course</p>
</div>
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Jag around the park 3k</p>
</div>
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">10 minutes meditation</p>
</div>
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Read for 1 hour</p>
</div>
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Pick up groceries</p>
</div>
<div class="NewTODO">
<div class="CheckBox"></div>
<p class="NameToDo">Complete all the Todo</p>
</div>
</div>
Le css :
.NewTODO {
display: flex;
align-items: center;
margin-bottom: 50px;
padding: 15px;
border-radius: 10px;
background-color: hsl(235, 24%, 19%);
}
.NewTODO p {
margin-left: 15px;
}
.CheckBox {
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #555;
border-radius: 50%;
height: 30px;
width: 30px;
cursor: pointer;
}
.Content {
display: flex;
flex-direction: column;
border-radius: 10px;
}
.Content .NewTODO {
margin: 0;
border-radius: 0;
}
.Content .NewTODO:first-child {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.Content .NewTODO:last-child {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
Le JavaScript :
var CheckBox = document.getElementsByClassName("CheckBox");
var n = 0
var NameToDo = document.getElementsByClassName("NameToDo")
CheckBox.addEventListener("click", () => {
if (n % 2 === 0) {
CheckBox.style.background = "linear-gradient(hsl(192, 100%, 67%), hsl(280, 87%, 65%))";
CheckBox.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="11" height="9"><path fill="none" stroke="#FFF" stroke-width="2" d="M1 4.304L3.696 7l6-6"/></svg>';
NameToDo.style.textDecoration = "line-through"
NameToDo.style.color = "#999"
n ++;
}
else {
CheckBox.style.background = "";
CheckBox.innerHTML = '';
NameToDo.style.textDecoration = ""
NameToDo.style.color = "#F1F1F1"
n ++;
};
});
cordialement