Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
one element to change color while hovering another one

This is what I tried so far. As they are in different divs and in no parent, sibling or child relation with each other, by my understanding CSS is no valid option.

 <script>
var circleOne = document.querySelector('.first_circle');
var adressOne = document.querySelector('.first_adress');

if (circleOne.matches(':hover')) {
    adressOne.style.color='green'; 
} else {
    adressOne.style.color='black';
}

</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use a combination of onmouseenter and onmouseleave

var circleOne = document.querySelector('.first_circle');
var adressOne = document.querySelector('.first_adress');

circleOne.onmouseenter = () => adressOne.style.color='green';
circleOne.onmouseleave = () => adressOne.style.color='black';
<div class="first_circle">First Circle</div>
<div class="first_adress">First Address</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

You should use mouseenter, mouseleave event listeners for this task

const firstEl = document.getElementById('first');
const secondEl = document.getElementById('second');

firstEl.addEventListener('mouseenter', () => secondEl.style.background = 'black');
firstEl.addEventListener('mouseleave', () => secondEl.style.background = 'transparent');

secondEl.addEventListener('mouseenter', () => firstEl.style.background = 'blue');
secondEl.addEventListener('mouseleave', () => firstEl.style.background = 'transparent');
#first, #second {
  display: inline-block;
  width: 100px;
  height: 100px;
  border: 1px solid #e0e0e0;
}
<div id="first"></div>
<div id="second"></div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda