html - Adding hyperlink to image in javascript array -
i have question. found topics on none answered question had array done in different way.
so have got javasript array images , 2 buttons next , previous. add hyperlinks pictures in array when cycle through them via buttons can click them , enter mentioned sites.
so html done this:
<div id="leftbox"> <p id="leftpopis"> whats new on web? </p> <img src="obrazky/0.png" id="imgdemo" > <button onclick="prvs()" id="btntwo"> <img src="obrazky/left.png"/> </button> <button onclick="nxt()" id="btnone"> <img src="obrazky/right.png"/> </button>
and javasript this:
<script> var img = new array("obrazky/0.png","obrazky/1.png","obrazky/2.png","obrazky/3.png"); var imgelement = document.getelementbyid("imgdemo"); var = 0; var imglen = img.length; function nxt() { if(i < imglen-1) { i++; } else{ i=0; } imgelement.src = img[i]; } function prvs() { if(i > 0) { i--; } else { = imglen-1; } imgelement.src = img[i]; }
it funcional in way swithces pictures when want add array:
var img = new array array("<a href="comments.html"> obrazky/0.png"</a>);
it doesnt work. got idea how update array works intended?
thanks :))
at first glance, may missing other things, looks accidentally exiting string , not including anchor tag.
var img = new array("<a href="comments.html"> obrazky/0.png"</a>);
you have couple options here. can use single-quotes (and include a tag) this
var img = new array("<a href='comments.html'> obrazky/0.png</a>");
or think can use literal string here using backtick (under ~squiggly)
var img = new array(`<a href="comments.html"> obrazky/0.png</a>`);
Comments
Post a Comment