Seeking assistance in individually changing the color of each square element that is generated one at a time in a row of five, with an id="square" tag. When I click the clickMe() function, I want each square to randomly change color. However, currently only one square changes while the rest remain unchanged after being created. Initial attempt using square as a class led all squares to change colors simultaneously.
Can someone guide me on how to assign a random color to each square separately when the clickMe() function is triggered? For instance, if I have one square and click the button, it should generate a random color for that particular square. Similarly, when two or more squares are present and the button is clicked, each square should receive a different random color simultaneously. This behavior should continue for every additional square cloned using the cloneMe() button.
Thus far, I've encountered issues where only one square can be changed after cloning, or all squares change together (when using a .class element) in synchronization.
var myColors = ['red', 'purple', '#E84751', 'blue', 'orange', '#323643', '#97FF73', '#362EFF', '#FF6513'];
function clickMe(){
var randomize = Math.floor(Math.random()*myColors.length);
$("#square").css("background-color", myColors[randomize]);
}
function cloneMe(){
$(document).ready(function(){
$("#square").clone().appendTo('.orange-square-container');
clickMe();
});
<!DOCTYPE html>
<html>
<head>
<title>Random Colors!</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script src="app.js"></script>
<div class="btn-alt-container">
<a class="btn btn1-alt" onclick='clickMe()'>Push Me</a>
<div class="btn btn2-alt" onclick='cloneMe()'>Make More</div>
</div>
<div class="container"
></div>
<div class="orange-square-container">
<div id="square">
<div class="content">
Hack Reactor's Awesome :)
</div>
</div>
</div>
</body>
</html>enter code here
Preview of the code in browser
Grateful for any advice provided here. Hoping to find solutions to coding challenges without hesitation in the future.