I would like to show three playing cards created and styled in HTML and CSS randomly without repeat. Basically I would like the cards to be randomly selected by id and shown. I know that there are other methods of doing this (i.e creating the deck itself in Javascript) but I would prefer to find a way to show the elements of the HTML by id using Javascript as it could be repurposed for showing other html elements styled in css like images, text, or anything with an ID three at a time, or even more at a time. I would also like this to be an onclick event.
With the below code, I have tried to put the ids in an array, but when I run the code the text within the brackets is showing up on the page rather than the id'd elements themselves. This is also occurring on load rather than on click. Please note that the ellipses in the code are not in the code, they are just there to signify the remaining elements. I've done some thorough research to try and find a way to do this an tried many methods, but haven't found a way to show more than one element at once (most examples of seen use the getElementById method which only works for one). The methods I've seen for multiple show text elements from the array. Does anyone have an idea how to make the code work in the way I've specified, or an alternate idea?
HTML:
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<link rel="stylesheet" type="text/css" href=style.css>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type"text/javascript" src="js/main.js"></script>
</head>
<div class="card">
<div style="font-size: 24px" style="display; inline-block">
<div class="cards" id="card1"><span style="color: #C23B22">2♦</span></div>
<div class="cards" id="card2"><span style="color: #C23B22">2♥</span></div>
<div class="cards"id="card3">2♣</div>
<div class="cards" id="car4">2♠</div>
<div class="cards" id="card5"><span style="color: #C23B22">3♦</span></div>
<div class="cards" id="card6"><span style="color: #C23B22">3♥</span></div>
<div class="cards" id="card7">3♠</div>
<div class="cards" id="card8">3♣</div>
<div class="cards" id="card9"><span style="color: #C23B22">4♦</span></div>
<div class="cards" id="card10"><span style="color:#C23B22">4♥</span></div>
<div class="cards" id="card11">4♣</div>
<div class="cards" id="card12">4♠</div>
<div class="cards" id="card13"><span style="color:#C23B22">5♦</span></div>
<div class="cards" id="card14"><span style="color:#C23B22">5♥</span></div>
<div class="cards" id="card15">5♣</div>
...
</div>
</div>
<input type="button" id="Button" value="Random" onclick="RandomDiv();" />
</body>
</html>
Javascript/Jquery:
var myarray = ["card1","card2","card3","card4","card5","card6","card7","card8","card9","card10","card11","card12","card13","card14","card15"...];
var numberOfTestimonials = 3;
for (var i=1; i<=numberOfTestimonials; i++) {
var randomIndex = RandomDiv(myarray);
$('.card').append(myarray[randomIndex]);
myarray.splice(randomIndex, 1);
}
function RandomDiv(myarray) {
return Math.floor(Math.random() * myarray.length);
};