Reputation: 1169
I've been trying to learn how to incorporate jQuery into an HTML program, and I'd appreciate if anyone could help me figure out what is wrong with the following code:
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).ready(function(){
alert("I'm ready!");
}):
</script>
</head>
<body>
<p> Hi there, I'm using Jquery </p>
</body>
</html>
I'm just trying to make a basic program that displays an alert box when it opens. For some reason, the alert box isn't popping up. Am I using the script tag in the wrong way?
Upvotes: 0
Views: 487
Reputation: 10281
2 problems:
src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
Add http:
before the //
. Your browser is attempting to find the file on your local fielsystem.
And }):
should be });
. Should work after that.
Upvotes: 1
Reputation: 1593
Change
$(window).ready(function(){
alert("I'm ready!");
}):
TO
$(document).ready(function(){
alert("I'm ready!");
});
You can check out the differences between and their uses here.
Upvotes: 0
Reputation: 1525
See jQuery ready()
$( document ).ready( handler )
// or
$().ready( handler ) (this is not recommended)
// or
$( handler )
Upvotes: 0