JQuery problem with Javascript in head tag

J

John Morrill

Greetings!

When I create a simple page like this!

<html>
<head>
<title>Test</title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript" />
<script type="text/javascript">
alert("From Head");
</script>
</head>
<body>
<span>Click me!</span>
<script type="text/javascript">
alert("From Body");
</script>
</body>
</html>

Only the second alert is displayed. When I comment out the jquery library as
shown below, both alerts are shown.

<html>
<head>
<title>Test</title>
<!--
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript" />
-->
<script type="text/javascript">
alert("From Head");
</script>
</head>
<body>
<span>Click me!</span>
<script type="text/javascript">
alert("From Body");
</script>
</body>
</html>

The jquery library is the one supply with VS2010. I am sure I am doing
something obvious wrong, but I can not see it.

Also, if this is not a forum that Microsoft engineers support, can some
please let me know. I assume comming from the MSDN page, I got that right
one. But in the past I made a mistake and keep wait for a reply.
 
J

John Morrill

Greetings All!

I found the problem. I knew it was something weird. The corrent script tag
is:
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

not

<script src="Scripts/jquery-1.4.1.js" type="text/javascript" />

This is a strange idiosyncrasy which appears to confuse those of us that
work a lot with XML. It appears that some XHTML tags should not be self
closing even if they do not contain any text. I hope this will help someone
else.

For the Microsoft engineers, may I sugguest a change to Visual Studio to
warn about this problem?

Cheers!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top