Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  44] [ 7]  / answers: 1 / hits: 16880  / 11 Years ago, fri, june 7, 2013, 12:00:00

Is $(document).ready() called after loading script js files in the body ?



If I put $(document).ready() in the head in script element which take a callback function that using a functions declared in a file which its script element loaded in the body like that :



<!DOCTYPE HTML>
<html>
<script src=jquery.js type=text/javascript></script>
<script>
$(function(){
hello();
})
</script>
<head>
</head>
<body>

<script src=http://somewhere/helloFuncDeclaration.js type=text/javascript></script>

</body>
</html>


Is it a right way to do that and guarantee that the helloFuncDeclaration.js will be loaded before calling the function hello() ?


More From » jquery

 Answers
21

To be sure, use window onload handler:



$(window).on('load', hello);


Or use it like this:



<script onload=hello() src=http://somewhere/helloFuncDeclaration.js type=text/javascript></script>

[#77758] Thursday, June 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;