0

I trie to get every the previouselementSibling of a div, but stil have problems with that. There is a way to get this?


garrafinhas.forEach((garrafa,indice)=>{
    garrafa.addEventListener('click',()=>{
        if(garrafa.classList.contains('garrafinha') ){
            garrafa.classList.remove('garrafinha')
        }
        else
        {
            while(garrafa.previousElementSibling !== 0){
                garrafa = garrafa.previousElementSibling;
                garrafa.classList.add('garrafinha')
                garrafa.classList.add('garrafinha')
            }
        }
        console.log(indice, garrafinhas.length)
    })
})

Azure.736
  • 1
  • 1
  • garrafa.classList.add('garrafinha') ocorres two times, but i remove this line and the problem continues – Azure.736 Aug 16 '23 at 14:42
  • `while(garrafa.previousElementSibling !== 0)` it’s never going to be exactly equal to zero. What if you remove `!== 0`? – James Aug 16 '23 at 14:58

0 Answers0