Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda