0

I just finished codecademy tutorials on html, css, js and jQuery. Now I am trying to create something on my own. But I can't make even the simplest thing work. I did everything in some kind of "browser consele lab" till now. Question is, how do I use or include jQuery in my index.html so it will work when I open it in browser? After some searching I used google hosted libraries links but it still doesn't work. I have 3 files created: index.html, style.css and script.js.

Now it just loads page with that square on it, but does nothing when I click it, even tho my jQuery code should be correct.

index.html code:

<!DOCTYPE html>
<html>
<head>
    <title>My thing</title>
    <link rel='stylesheet' type='text/css' href='style.css'/>
    <script type='text/javascript' src='script.js'></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

</head>
<body>
    <div>
    </div>
</body>
</html>

style.css code:

div {
height: 250px;
width: 250px;
background-color: #008800;
}

script.js code:

$(document).ready(function(){
  $('div').click(function(){
      $(this).effect('explode');
  });
});
0

3 Answers 3

3

it should be

<!DOCTYPE html>
<html>
<head>
    <title>My thing</title>
    <link rel='stylesheet' type='text/css' href='style.css'/>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script type='text/javascript' src='script.js'></script>

</head>
<body>
    <div>
    </div>
</body>
</html>

Your script page script.js used jQuery, so it should be included after jQuery library

Demo: Plunker

Sign up to request clarification or add additional context in comments.

3 Comments

Combination of adding http: and moving my 'script.js' link after those links worked.
@ruby_ruby there is no need to add http: as I shown in the demo
I see it works in demo, but when I delete the http: in my file it realy doesn't explode. When I keep it there it works. Anyway thank you for helping a newbie out.
0

You are missing the protocol part from your script source URLs. Add either http: or https: depending on where you are getting them from.

1 Comment

that is fine, it will use the protocol used to load the index page
0
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

you miss the http: try this one and see if it works

1 Comment

that is fine, it will use the protocol used to load the index page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.