jQuery not working locally or via CDN

Associate
Joined
10 Feb 2009
Posts
1,893
Location
Leicester
Only get 3 results on google but can anyone help?

This is the code:

Code:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style>
div {
	background-color: red;
}
a.test {
	font-size: 22px;
}
</style>
</head>

<body>

<script type="text/javascript">
$(document).ready(function() {
 $('a').addClass('a.test');
});
});
</script>

<div>
<p>some text</p>
</div>

<a href="asda">aa</a>

</body>
</html>

Should work right?

When I put in an alert message it works.. but when I try to code in jquery it doesn't .. :s
 
Last edited:
Associate
Joined
30 Apr 2004
Posts
50
Aren't you missing the http from the cdn link?

PHP:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

PHP:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style>
div {
	background-color: red;
}
a.test {
	font-size: 22px;
}
</style>
</head>

<body>

<script type="text/javascript">
$(document).ready(function() {
 $('a').addClass('test');
});
</script>

<div>
<p>some text</p>
</div>

<a href="asda">aa</a>

</body>
</html>
 
Associate
OP
Joined
10 Feb 2009
Posts
1,893
Location
Leicester
Aren't you missing the http from the cdn link?

PHP:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

PHP:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style>
div {
	background-color: red;
}
a.test {
	font-size: 22px;
}
</style>
</head>

<body>

<script type="text/javascript">
$(document).ready(function() {
 $('a').addClass('test');
});
</script>

<div>
<p>some text</p>
</div>

<a href="asda">aa</a>

</body>
</html>

The http is missing so it works on both http and https (apparently), I just tried adding it and it still don't work.. the syntax change didn't make a difference either.. :confused:

edit:

adding http:// seems to of worked now along with changing a.test in the script to just 'test'.. local still not working though, think I need the jqueryUI for effects?
 
Last edited:
Soldato
Joined
9 May 2005
Posts
4,524
Location
Nottingham
I'm not sure you can exclude the http/https from the CDN link when you're running from a file.

When your running from a file and exclude the protocol it will be using "file://" instead so it would work if you had the file in the correct location locally /ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js

The other option would be to use a local web server on your machine.
 
Back
Top Bottom