I'm using this code:
if ( selectColor.value == "R" & selectDiv.value == "grandParent" ) {
grandParent.children[0].classList.add("red")
}
if ( selectColor.value == "R" & selectDiv.value == "parent-1" & parent1.children[0].contains('red') == false) {
parent1.children[0].classList.add("red")
}
The first if statement works fine. The second doesn't. What I'm trying to do is check if a div has a class or not, if not, add the selected color class,if it already has a class, remove it and add the new selected class.
I couldn't get to the answer of this exact logic myself using others posts. I'm learning with no live help for 4 months (until now) through internet courses, so bear with me if you can.
Let's break your problem into sub-problems:-