here is the code :
square.addEventListener("click", function(e){
if (square.style.background = "yellow"){
document.getElementById("header").appendChild(firstChapter);
document.getElementById("header").appendChild(secondChapter);
document.getElementById("header").appendChild(thirdChapter);
document.getElementById("header").appendChild(fourthChapter);
square.style.background = "red";
}
if (square.style.background = "red") {
document.getElementById("header").removeChild(fourthChapter);
square.style.background = "yellow";
}
});
So the first click event should add these childs and change square color red Then if it is red, delete childs (i put only one just for example) and goes back to yellow Problem is when i click it, both of the conditions are executed in the same time and the outcome is a yellow square with three childs i'm pretty sure there is a simple solution but i can't figured it