0
I’m a beginner in javascript, I can’t figure out the right syntax for coding to work. Note: I am trying to make the image toggle every click.
HTML)
<label id='a'>
<img class='cadeira' src='./img/cadeira.png'/>
<img class='cadeira2' src='./img/cadeira2.png'/>
</label>
JS)
function toggleImage(){
const elChildren = document.getElementById("a").children;
const img2 = elChildren[1];
if(img2.style.display=="none"){
img2.style.display="block";
console.log("trocou");
}
else{
img2.style.display="none";
console.log("não trocou");
}
}
function eventos(){
const cadeira=document.getElementById("a");
cadeira.addEventListener("click",toggleImage);
}
window.addEventListener("load",eventos);
My console.log eventually returns to "not changed".
If anyone can help me please, I really need that code for a project very soon. Thank you so much already.
Has there been any response?
– novic
It worked obg, and I got enough base, now I’m trying a way with several Labels kkkkk.
– Isa Bella