This one must be very simple. An external javascript file contains:
function Hello() {
alert('Hello');
}
It is getScript()
ed and then a contained function is called
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.getScript('myscript.js');
Hello();
</script>
I get:
ReferenceError: Hello is not defined
But if the script is referenced in an HTML <script>
tag it works as expected
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="myscript.js" type="text/javascript"></script>
<script type="text/javascript">
Hello();
</script>
What I am missing? How to reference objects created in a getScript()
ed script? The reason I want to use getScript()
it to load the script on a ready()
event.