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

222
Visualizações
Click handler not working for <div> with <object> as child

I have just two elements, a div with an object attached as child, which contains an SVG image. The click handler works fine when there is just the div by itself, or another tag as it's child, such as img. However, when the object is a child, the div click handler is only triggered in the very bottom right corner. I'm really stuck as to what would be causing this behavior.

let divContainer = document.createElement('div');
divContainer.className = 'divContainer';
divContainer.style.position = 'absolute'
divContainer.style.top = '100px';
divContainer.style.width = '150px';
divContainer.style.height = '150px';
divContainer.style.background = 'green';
  
let imageChild = document.createElement('object');
imageChild.type = 'image/svg+xml';
imageChild.data = 'https://svgsilh.com/svg_v2/48363.svg'
imageChild.className = 'imageChild';
imageChild.style.width = 'inherit';
   
document.body.append(divContainer);
// Comment this out, and it works fine
divContainer.append(imageChild);

divContainer.onclick = function(event) {
  console.log('Click OK!');
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

here is the working code

  let divContainer = document.createElement('div');
  divContainer.className = 'divContainer';
  divContainer.style.top = '100px';
  divContainer.style.width = '150px';
  divContainer.style.height = '150px';
  divContainer.style.background = 'green';

  let imageChild = document.createElement('object');
  imageChild.type = 'image/svg+xml';
  imageChild.data = 'https://svgsilh.com/svg_v2/48363.svg';
  imageChild.className = 'imageChild';
  imageChild.style.width = 'inherit';
  imageChild.style.pointerEvents = 'none';

  document.body.append(divContainer);
  // Comment this out, and it works fine
  divContainer.append(imageChild);

  divContainer.addEventListener('click', function () {
    alert('Click OK!');
  });
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