var types = ['hearts', 'diamonds', 'clubs', 'spades'],
type1, type2, no1, no2;
function shuffle() {
$('#card1')
.removeClass(type1)
.removeClass('c' + no1);
$('#card2')
.removeClass(type2)
.removeClass('c' + no2);
type1 = types[Math.floor(Math.random() * types.length)],
type2 = types[Math.floor(Math.random() * types.length)],
no1 = 1 + Math.floor(Math.random() * 11),
no2 = 1 + Math.floor(Math.random() * 11);
$('#card1')
.removeClass('back')
.addClass(type1)
.addClass('c' + no1);
$('#card2')
.removeClass('back')
.addClass(type2)
.addClass('c' + no2);
if (type1 == type2 && no1 == no2) {
console.log('Match!!!');
}
}
.card {
position: relative;
display: inline-block;
background: url('https://cmkt-image-prd.global.ssl.fastly.net/0.1.0/ps/2502319/1160/772/m1/fpnw/wm0/12-playing-card-icons-1-.png?1491379334&s=8d4af6f2f06ee5cf0c53b95573d43e02');
background-repeat: no-repeat;
width: 105px;
height: 152px;
}
.back {
background-position: -823px -334px;
}
.label-top::before {
position: absolute;
top: 15px;
left: 35px;
}
.label-bottom::before {
position: absolute;
bottom: 15px;
right: 35px;
}
.rotate::before {
transform: rotate(180deg);
/* Safari */
-webkit-transform: rotate(180deg);
/* Firefox */
-moz-transform: rotate(180deg);
/* IE */
-ms-transform: rotate(180deg);
/* Opera */
-o-transform: rotate(180deg);
/* Internet Explorer */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}
.hearts {
color: red;
background-position: -220px -121px;
}
.diamonds {
color: red;
background-position: -826px -121px;
}
.clubs {
color: black;
background-position: -630px -121px;
}
.spades {
color: black;
background-position: -425px -121px;
}
.back>.label-top::before,
.back>.label-bottom::before {
content: "";
}
.c1>.label-top::before,
.c1>.label-bottom::before {
content: "1";
}
.c2>.label-top::before,
.c2>.label-bottom::before {
content: "2";
}
.c3>.label-top::before,
.c3>.label-bottom::before {
content: "3";
}
.c4>.label-top::before,
.c4>.label-bottom::before {
content: "4";
}
.c5>.label-top::before,
.c5>.label-bottom::before {
content: "5";
}
.c6>.label-top::before,
.c6>.label-bottom::before {
content: "6";
}
.c7>.label-top::before,
.c7>.label-bottom::before {
content: "7";
}
.c8>.label-top::before,
.c8>.label-bottom::before {
content: "8";
}
.c9>.label-top::before,
.c9>.label-bottom::before {
content: "9";
}
.c10>.label-top::before,
.c10>.label-bottom::before {
content: "10";
}
.c11>.label-top::before,
.c11>.label-bottom::before {
content: "A";
}
.c12>.label-top::before,
.c12>.label-bottom::before {
content: "J";
}
.c13>.label-top::before,
.c13>.label-bottom::before {
content: "Q";
}
.c14>.label-top::before,
.c14>.label-bottom::before {
content: "k";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="card1" class="card back">
<b class="label-top"></b><b class="label-bottom rotate"></b>
</div>
<div id="card2" class="card back">
<b class="label-top"></b><b class="label-bottom rotate"></b>
</div>
<br />
<button onclick="shuffle()">Shuffle</button>