0

I have a box2 with <img /> inside it.

I have used a random image selection function for selecting random images,

I want to display the randomly selected image one by one to the image src of class box2.

How do I achieve it?

I use

function rvalue() {

  var array = [];
  var tempimages = [];


  var ArrayOfImages = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg', '16.jpg', '17.jpg', '18.jpg', '19.jpg', '20.jpg'];

  arrayLength = ArrayOfImages.length;

  for (i = 0; i < arrayLength; i++) {
    array[i] = ArrayOfImages[Math.floor(Math.random() * arrayLength)];

  }

  console.log(tempimages);
}
.box {
  float: left;
  width: 50px;
  height: 50px;
  margin-left: 30%;
  padding-top: 2%;
  background-color: #ff9900 2px;
}
<body onload="rvalue">
  <div class="box" id="2">
    <img src="" draggable="true" id="slide" style="width:100px; height:100px; border-radius: 50%;" border="rounded" />
  </div>
</body>
Ramesh
  • 2,297
  • 2
  • 20
  • 42
geek
  • 205
  • 1
  • 9

0 Answers0