Hello. How to randomly generate photos? via html javascript to click on the button it generated photos from the folder

Closed due to the fact that the essence of the issue is not clear to the participants of Kromster , Denis , lexxl , Regent , Vadim Ovchinnikov Jan 19 '17 at 14:22 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Can you explain what you want to see? example - L. Vadim
  • For example, clicking on the button appeared 1 photo clicking again the photo changed randomly - Karen Hovhannisyan

1 answer 1

Randomly selects, but maybe several times select one photo.

var images = [ "https://s27.postimg.org/a6iaie0tb/image.png", "https://s27.postimg.org/euyadkpzz/image.png", "https://s27.postimg.org/i37d4d1nj/image.png", "https://s27.postimg.org/99ggn9eov/image.png", "https://s27.postimg.org/lww7zrtlr/image.png" ]; $(document).ready(function(){ $("#bt").on("click", function(){ var rand = Math.floor((Math.random() * 5)); $("#show").attr("src",images[rand]); }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div><img id="show" src="https://s27.postimg.org/a6iaie0tb/image.png"></div> <button id="bt">Change images</button>