javascript - Default image's display doesn't change despite the source of the image changing. -
var allimages = [imagedata, imagedata1, imagedata2, imagedata3, imagedata4]; var count = 0; $("#right").click(function() { if (count < 5){ document.getelementbyid("hello").src = allimages[count]; count++; } });
to explain code, array allimages contains base64 versions of 5 images. #hello id of default image. #right id of button.
so when click #right, #hello's source supposed change 1 of images inside allimages array. however, nothing happens display when click #right.
i've tried changing source outside of right click function , when that, display of #hello correctly change. in addition that, #right click function work cause i've stuck alert inside of before activated upon click.
probably need check value of count .
quite possible count being global variable other block of code might have been updating value leading (count < 5) = false
.
suggestion : try after renaming variable or removing if condition , setting hard-coded value of src attribute
Comments
Post a Comment