/    Sign up×
Community /Pin to ProfileBookmark

I’m trying to learn Jquery from codeacademy.com but i can’t get my code to work.

It works in the codeacademy.com website but not in my text file. The following html, css and jquery are supposed to make the div boxes shrink and grown when you mouse hover over them. But they dont. Whats wrong with it? I even tried linking the google hosted java thingy (4th line in the html) and it doesn’t say to necessarily do that. But even that didn’t help.

Here’s the html :

<!DOCTYPE html>
<html>
<head>
<script src=”//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js” type=”text/javascript”></script>
<title>Magic!</title>
<link rel=”stylesheet” type=”text/css” href=”stylesheet.css”/>
<script type=”text/javascript” src=”script.js”></script>
</head>
<body>
<div id=”red”></div>
<div id=”blue”></div>
<div id=”yellow”></div>
<div id=”green”></div>
</body>
</html>

And here’s the css :

div {
height:100px;
width:100px;
display: inline-block;
}

#red {
background-color:#FF0000;
}

#blue {
background-color:#0000FF;
}

#yellow {
background-color:#E2BE22;
}

#green {
background-color:#008800;
}

And lastly, here’s the java :

$(document).ready(function() {
$(‘div’).mouseenter(function() {
$(this).animate({
height: ‘+=10px’
});
});
$(‘div’).mouseleave(function() {
$(this).animate({
height: ‘-=10px’
});
});
$(‘div’).click(function() {
$(this).toggle(1000);
});
});

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@haulinFeb 23.2013 — Yes, you do need to include that google hosted thingy, since it's a jQuery library and without it, you can't use any of that $(something) fancy stuff. However, you have a typo in it's address:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

<script src="[B][COLOR="#FF0000"]http:[/COLOR][/B]//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

And for heaven's sake, Java and Javascript are two different things. You are learning Javascript :mad:
Copy linkTweet thisAlerts:
@matth1980authorFeb 23.2013 — Thanks so much for the help. I'll try it.
Copy linkTweet thisAlerts:
@haulinFeb 25.2013 — Actually, it's not a typo, it's protocol relative URL, however, if you access your script via a local file, it will try to request it via [B]file://[/B], which won't work...
×

Success!

Help @matth1980 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...