Matt
Matt

Reputation: 1169

How to include jQuery in HTML?

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

Answers (3)

EML
EML

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

Akash Rajbanshi
Akash Rajbanshi

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

Jake Opena
Jake Opena

Reputation: 1525

See jQuery ready()

$( document ).ready( handler )
// or
$().ready( handler ) (this is not recommended)
// or
$( handler )

Upvotes: 0

Related Questions