[Solved] How do I display a different image everytime the image is clicked? [closed]


If you are using html js and css:

jsfiddle http://jsfiddle.net/harshdand/dec2mpbv/

html:

<img src="http://picture-gallery.dnspk.com/albums/userpics/10001/normal_1124750273-15.jpg" id="images"/>

js

  1. make an array of images u want

    var currentImageIndex = 0;
    
    var images=[
        'http://picture-gallery.dnspk.com/albums/userpics/10001/normal_1124750273-15.jpg',
        'http://images7.alphacoders.com/408/thumbbig-408758.jpg',
        'http://images6.alphacoders.com/410/thumbbig-410020.jpg',
        'http://picture-gallery.dnspk.com/albums/userpics/10001/normal_1127034390-11.jpg'
    ];
    

    document.getElementById(‘images’).setAttribute(‘src’,images[0]);

    document.getElementById('images').onclick = function(){
        if(currentImageIndex<images.length-1)
            currentImageIndex++;
        else
            currentImageIndex = 0;
         document.getElementById('images').setAttribute('src',images[currentImageIndex]);
    }
    

solved How do I display a different image everytime the image is clicked? [closed]