Reputation: 41
I have these javascript files in my project:
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- Latest compiled and minified Bootstrap JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!--Game Script-->
<script type="text/javascript" src="script.js"></script>
The bottom one isn't working when I load up the page. Why might that be?
The html file and the script.js file are located in the same folder.
Look at the entire project here if you like: https://github.com/samjb2/IncrementalRPG. The document in question is game.html.
Upvotes: 0
Views: 91
Reputation: 4840
Add your jquery event click handlers inside of the
$(document).ready(function(){
// handlers go here
});
It seems like you need to wait for your page to load before you start attaching handlers to elements on your page. I moved them inside of $(document).ready() and I was able to click on "Chop Wood" and see it increment a value.
Upvotes: 0
Reputation: 324610
I'm going to take a shot in the dark here, because everything looks right. This is kind of one of those guesses where you look at things out of the corner of your eye and notice something that's not quite right. Or maybe I've been playing too much Phoenix Wright.
I submit that you are running your game.html
file locally - that is, the URL in your browser's address bar looks like this:
file:///C:/Users/Niet/Documents/game.html
In this case, your problem stems from this:
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
The //
resolves the address relative to the current scheme. In other words, it's looking for:
file:///netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js
Needless to say, I'm pretty sure that file does not exist!
Try using this instead:
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
By explicitly stating the scheme, you avoid the problem of relative paths.
Alternatively, try running your game from a server, for example if you set one up on your computer you could try:
http://localhost/game.html
Again, if this works, I was right!
Upvotes: 1
Reputation: 17064
Use Fiddler and when the page loads up, watch the results. I'm guessing you'll see a 404 not found error on the "script.js" request.
This is probably your problem, perhaps you should try /script.js
, but it's hard to tell without knowing where your file is located.
Upvotes: 0