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

160
Vistas
JS Need help to add href on img

i'm using Innova Content Builder to record my webpage. It's contains a module called saveimage.php which transforms binary images to jpg files. This works perfectly.

Now, i would like to encapsulate these img whith href links, but it doesn't works.

Here is my code :

parent.document.getElementById('img-" . $count . "').setAttribute('src','" . $urlpath . $image . "');
parent.document.getElementById('img-" . $count . "').setAttribute('alt','".$image."');
var myLink = document.createElement('a');
myLink.setAttribute('href','http://www.google.fr');
parent.document.getElementById('img-" . $count . "').appendChild(myLink);

This code is placed into a body onload function. I think it's a parentality problem.

Can you help me ? Thanks !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use this:

<script>
    parent.document.getElementById('img-" . $count . "').setAttribute('src','" . $urlpath . $image . "');
    parent.document.getElementById('img-" . $count . "').setAttribute('alt','".$image."');
var myLink = document.createElement('a');
myLink.setAttribute('href','http://www.google.fr');
    parent.document.getElementById('img-" . $count . "').parentNode.insertBefore(myLink, parent.document.getElementById('img-" . $count . "'));
    myLink.appendChild(parent.document.getElementById('img-" . $count . "'));
</script>
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