• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

132
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 !

almost 3 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>
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error