Reputation: 17
I can't understand what is wrong with this. It may be a linking problem, but i can't tell wich one. index.html, script.js and jquery's library files are in my desktop. This is the code:
This is the HTML code:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1>asdasd</h1>
</body>
</html>
This is the Jquery external sheet:
$(document).ready((function) {
("h1").click((function) {
(this).hide();
});
});
There's no CSS sheet, because I made it simple, so I could be sure it's not wrong, but maybe it is.
Upvotes: 1
Views: 111
Reputation: 7821
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
You need to add http:
to your script
's src
attribute
You should pull this from your own server though. As Crockford says:
Use your own copy. It is extremely unwise to load code from servers you do not control.
Also the code block is a little wrong:
$(document).ready(function () {
$("h1").click(function () {
$(this).hide();
});
});
Upvotes: 0
Reputation: 70199
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
Protocol-less URLs do not work through the file:///
scheme.
Put an http://
in place of //
and it should work. However, using a localhost server is a better way around in the long term. =]
With a localhost server you can run your page through http://
easily so it gets you through that error and many other file permission issues that you may run into in the future. Here are a few easy to install servers: WAMP, EasyPHP, XAMPP, BitNami
Also (function)
should be function()
and you're missing a $
:
$(document).ready((function) {
("h1").click((function) {
Should be
$(document).ready(function() {
$("h1").click(function() {
Try running your code through JSHint, it will find those basic syntax errors for you.
Upvotes: 3