0
When I click on any of these cans the background would change color and the main can too :
Only that the background of the second Section is not changing color(And it has the same
class
) :
Obs : I want the upper class to be the same color as the lower class.
- HTML
<!--Primeira <section> -->
<section class="corDeFundo">
</section>
<!-- Segunda <Section>-->
<section class="corDeFundo">
<div class="produto" id="produto">
<h1>produto</h1>
</div>
</section>
Javascript(Full)
const corDeFundo = document.querySelector(".corDeFundo") const latasDeRefri = document.querySelectorAll(".latasDeRefri li") const pepsiPrincipal = document.querySelector(".pepsi") latasDeRefri[0].addEventListener("click",()=>{ pepsiPrincipal.src = "imagem/pepsi1.png" corDeFundo.style.background = "#004999" corDeFundo.style.transition = "0.5s" }) latasDeRefri[1].addEventListener("click",()=>{ pepsiPrincipal.src = "imagem/pepsi2.png" corDeFundo.style.background = "#ED0223" corDeFundo.style.transition = "0.5s" }) latasDeRefri[2].addEventListener("click",()=>{ pepsiPrincipal.src = "imagem/pepsi3.png" corDeFundo.style.background = "#191C1E" corDeFundo.style.transition = "0.5s" })
uses the browser tool to investigate which method is setting the background, it would not be a div inside it, like the div with id "product"?
– Ricardo Pontual
I looked here , and what is defining the color is the class="corDeFundo", only that the effect is only applied in the first <Section class="corDeFundo">, and the effect has to be applied in the second <Section> with the same class.
– Valdenirson PEREIRA
I put the full html, take a look now
– Valdenirson PEREIRA
latasDeRefri[0]
this here, just like the others, using the zero index will change only the first item– Ricardo Pontual
latasDeRefri[0] will take the first can(Blue) and put as main and change the background color to blue , what is wrong ?
– Valdenirson PEREIRA
if you only have these elements no problem. Now as for the background, you are using the selector
document.querySelector
that brings 1 element, that is, will only change the first element with the class "corDeFundo", should usequerySelectorAll
and change all– Ricardo Pontual
really that’s it, THANK YOU!!! but how do I get all the items in the array ? (I did it using FOR, but if there’s another way comments on the answer to the question) , Obs: If you can give like in the question I thank you
– Valdenirson PEREIRA