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

308
Visualizações
How to increase clickable area to include sibling elements?
<div>
   <div class="child-1">Clickable child</div>
   <div class="child-2">Non-clickable child</div>
</div>

Let's say child-1 is clickable, and child-1 is a 3rd library element so I can't change it. Right now the clickable area is only child-1. How can I trigger child-1 click when I click child-2?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Add the onclick listener to the parent of the child-1 and child-2. That way, the event bubbles up to the parent div and you can act upon it accordingly.

Using event.target you can identify where the actual click happened (between child-1 and child-2)

<div id="wrapper">
   <div class="child-1">Clickable child</div>
   <div class="child-2">Non-clickable child</div>
</div>

JS:

 const wrapper = document.getElementById('wrapper');
 wrapper.addEventListener('click', (event) => { ... });
about 4 years ago · Juan Pablo Isaza Relatório

0

You can add a click event listener to click2 and then get that to trigger a click on click1 element.

const child1 = document.querySelector('.child-1');
const child2 = document.querySelector('.child-2');
child2.addEventListener('click', function() {
  alert('child2 clicked');
  child1.click();
});
child1.addEventListener('click', function() {
  alert('child1 clicked');
});
<div>
  <div class="child-1">Clickable child</div>
  <div class="child-2">Non-clickable child</div>
</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