javascript - Changing HTML image, function doesn't seem to be called -
i trying add source image through javascript, , jquery code found on internet, doesn't seem work:
<html> <head> <script src = "http://www.example.com/images/"> var count=1; var initnumber=100; function changeimage(){ count++; $("#htmlphoto").attr('src'+((initnumber+count).tostring)+".jpg"); } </script> </head> <body onload="changeimage()" > <img id="htmlphoto"/> <button onclick="changeimage()">next image</button> </body>
trying call once again changeimage()
function button clicks.
edit:managed make work, changed code bit, if wants see:
<html> <head> <script> var count=1; function nextimage(address){ count++; image = document.getelementbyid('htmlphoto'); image.src ="http://www.example.com/images/"+(address+count)+".jpg"; } </script> </head> <body> <img id="htmlphoto"/> <button onclick="nextimage(100)">next image</button> </body>
change:
$("#htmlphoto").attr('src'+((initnumber+count).tostring())+".jpg");
to:
$("#htmlphoto").attr('src', ((initnumber+count).tostring())+".jpg");
Comments
Post a Comment