lundi 3 mai 2021

How to insert a hyperlink on a image, using javascript

I have an image that I need to put a hyperlink on to another existing website, in javascript.

The image is already in a slideshow with 3 images and I need to link each specific image.

Does anyone know the solution to this?

I already tried the original method to hyperlink images through JSON, and it doesn't seem to work.

here is my code

document.getElementById("arrowLeft").addEventListener("click", () => {
  kogebog_billede_nummer - 1 === 0 ? kogebog_billede_nummer = 3 : kogebog_billede_nummer--
    document.getElementById("kogebogBillede").src = `${wordPressData[2].acf.kogebog_eksempel["kogebog_billede" + kogebog_billede_nummer].url}`;
});


document.getElementById("arrowRight").addEventListener("click", () => {
  kogebog_billede_nummer + 1 === 4 ? kogebog_billede_nummer = 1 : kogebog_billede_nummer++
    document.getElementById("kogebogBillede").src = `${wordPressData[2].acf.kogebog_eksempel["kogebog_billede" + kogebog_billede_nummer].url}`;
});
<div class="kogebogEksempel">
  <div class="arrowBox">
    <img id="arrowLeft" src="${wordPressData[2].acf.kogebog_eksempel.arrowleft.url}" alt="pil til venstre">
  </div>
  <img id="kogebogBillede" src="${wordPressData[2].acf.kogebog_eksempel.kogebog_billede1.url}" alt="Coveret til VEGANSK GRUNDKØKKEN">
  <div class="arrowBox">
    <img id="arrowRight" src="${wordPressData[2].acf.kogebog_eksempel.arrowright.url}" alt="pil til højre">
  </div>
</div>



Aucun commentaire:

Enregistrer un commentaire