Sunday, 8 September 2013

Jquery function no result if imported to soon?

Jquery function no result if imported to soon?

I created a simple function with Jquery and it works, but if I import it
to soon it doesn't work, for example
<html land="en">
<head>
<meta carset="utf-8">
<title> Jquery 2 </title>
</head>
<body>
<!-- Inline is JS in the HTML file -->
<p id="paragraph"> This is a paragraph </p>
<script src="jquery-1.10.2.min.js"></script>
<script src="Tutorial2.js"></script>
</body>
</html>
This works, but if I did this
<html land="en">
<head>
<meta carset="utf-8">
<script src="jquery-1.10.2.min.js"></script>
<script src="Tutorial2.js"></script>
<title> Jquery 2 </title>
</head>
<body>
<!-- Inline is JS in the HTML file -->
<p id="paragraph"> This is a paragraph </p>
</body>
</html>
This doesn't work.
Is it because my function in Tutorial2.js uses a reference to p
id="paragraph" and as the Javascript file is loaded before the page, the
function doesn't know what I am telling it to access. Is my assumption
correct?

No comments:

Post a Comment