I'm working with the code snippet below:
$(document).ready(function() {
$(".content-image").each(function() {
var angle = getRandomAngle();
$(".content-image").css("transform", "rotate(" + angle + "deg)");
});
});
function getRandomAngle() {
return Math.floor(Math.random() * 5) + 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class="content-image" src="https://via.placeholder.com/150" />
<img class="content-image" src="https://via.placeholder.com/150" />
Currently, this code rotates all images with the same angle. How can I make sure each image has a different angle?