Since I have a working version, I'll offer the details as a solution (it's too much for a comment) in hopes that some detail will be what's needed to correct the version you have that isn't working properly.
The three files I am using, that align with yours, I called so.html
, so.js
, and so.css
.
HTML:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>SO Test</title>
<link rel="stylesheet" type="text/css" href="/test/css/so.css" />
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script language="JavaScript" src="/test/script/so.js"></script>
</head>
<body>
<div class="container shuffleImg">
... <!-- here I named the images uniquely, "Image 1" through "Image 8";
otherwise same as your code -->
</div>
<button class="btn btn-danger" id="go">Shuffle</button>
<hr>
<button class="btn btn-danger" onClick="window.location.reload(true);">Reset</button>
</body>
</html>
JS:
//card flip function start
$(function() {
// No change here to your first definition of this function
});
function rotateCard(btn) {
//No change to this function
}
// card flip funtion end
// I hoisted shuffle out of the next $(function() ...) block since I use it again later
function shuffle() {
// No change to function content
}
//random function start
$(function() {
$("#go").on("click", shuffle);
});
$(window).load(function() {
shuffle()
});
//random funtion end
CSS I did not change at all.
Here's a test site using this code: Test.
Edit:
I am also using the latest jQuery library since the major providers offer links to "latest". I didn't notice anything particularly exotic in your jQuery code, but it's possible your problem could be that you're including old and/or unofficial version.
Edit:
Per the comments, you've indicated that you are using the "slim" package of jQuery. The "slim" package, as the name implies, does not include several particular features of jQuery. See this SO question, for example: What are the differences between normal and slim package of jQuery. In particular, the animation features which you use are not supported, nor is the .load
function. So the $(window).load(...)
will fail. This can be seen looking at the development console in the browser.