user845392
user845392

Reputation: 563

add External javascript file - Syntax issue

When i use the following syntax, the inline script is not executed. In Firebug not able to debug the code.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" type="text/javascript" />

<script>
$(document).ready(function () {
$('#btn').bind('click', function () {
alert('hai');
});
});
</script>

but if i change the external file add script, it works fine. no issues at all.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" type="text/javascript" > </script>

Upvotes: 0

Views: 653

Answers (4)

Igor Dymov
Igor Dymov

Reputation: 16460

You must close <script> tag.

W3.ORG:

Start tag: required, End tag: required

Upvotes: 1

Pafjo
Pafjo

Reputation: 5019

Your are closing the script tag too early. Remove the last slash from the first row.

Upvotes: 0

Fender
Fender

Reputation: 3055

the browser inserts the content from the url provided in the src attribute into the <script></script> tag. so if there is only a emtpy tag you can't insert anything

Upvotes: 0

genesis
genesis

Reputation: 50966

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

<script>
$(document).ready(function () {
$('#btn').bind('click', function () {
alert('hai');
});
});
</script>

script is html pair tag. You have to close it

BTW there's no reason to use https

Upvotes: 0

Related Questions