Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!