javascript - Linking JQuery into my html - Stack Overflow

I am trying to include an external jQuery file into my html (first time) but it isn't working, jus

I am trying to include an external jQuery file into my html (first time) but it isn't working, just executing the html without the jquery. (css is working fine)

Here's the html code:

<!doctype html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
</head>
<body>
  <script type="text/javascript" src="<script src=".min.js" />
  <script type="text/javascript" src="script.js"></script>
  <h1>Hello World!</h1>`
</body>
</html>

Here's the jquery code in script.js:

$(document).ready(function(){
   alert("it works");
});

And yes, they are all in the same folder (dropbox folder actually, but I don't think dropbox affects anything)

I am trying to include an external jQuery file into my html (first time) but it isn't working, just executing the html without the jquery. (css is working fine)

Here's the html code:

<!doctype html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
</head>
<body>
  <script type="text/javascript" src="<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js" />
  <script type="text/javascript" src="script.js"></script>
  <h1>Hello World!</h1>`
</body>
</html>

Here's the jquery code in script.js:

$(document).ready(function(){
   alert("it works");
});

And yes, they are all in the same folder (dropbox folder actually, but I don't think dropbox affects anything)

Share Improve this question edited Sep 12, 2013 at 1:13 Andrew Barber 40.2k20 gold badges97 silver badges124 bronze badges asked Sep 11, 2013 at 21:40 llpllp 801 gold badge2 silver badges7 bronze badges 4
  • 1 Where you read this script in source? give only your url in source – mit Commented Sep 11, 2013 at 21:45
  • FYI: It's generally accepted to not self-close your script tags - do <script src="..."></script> instead of <script src="..." />. I believe self-closing script tags work everywhere except old IE (IE7 maybe?), but people still generally don't do it. – Joe Enos Commented Sep 11, 2013 at 21:46
  • If you think about what you have done, you would end up in a Infinite loop because you would put the script in every src – iConnor Commented Sep 11, 2013 at 21:52
  • Best you can do is learn to debug this error by referring to developer tools for whatever browser you are using. Quick google will help you to get started with developer tools. – Mutant Commented Sep 11, 2013 at 22:00
Add a ment  | 

3 Answers 3

Reset to default 2
<script type="text/javascript" src="<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js" />
<script type="text/javascript" src="script.js"></script>

First, remove the extra src="<script inside your <script> tag. Also "close" it with a </script> tag...

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

Second, place the script includes at the end of your <body> section, just before the </body> tag:

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

OR, anywhere inside your <head> section:

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

And finally, make sure the URL path is correct for your version:

http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js

It's always smart to link to a full version. Otherwise, if the code at the URL is updated, your site could suddenly break without warning.


If you make the changes as indicated above and add a <title> element into your head section...

<head>
    <title>Title</title>
    ....

... your code will then pass HTML validation.

http://validator.w3/check

Is this a typo? You have an extra <script in your src=" "

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

should be

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

Change it to:

<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js"></script>

You have the full script inside the src, which is wrong.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745487126a4629815.html

相关推荐

  • javascript - Linking JQuery into my html - Stack Overflow

    I am trying to include an external jQuery file into my html (first time) but it isn't working, jus

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信